package com.easymin.weixin.common.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.easymin.weixin.common.SignHelper;
import com.easymin.weixin.common.transport.ResultVo;
import com.easymin.weixin.controller.v4.ResultTransport;
import com.easymin.weixin.controller.v5.utils.ErrorMapV5;
import com.easymin.weixin.controller.v5.utils.ResultV5;
import com.easymin.weixin.entity.area.Area;
import com.easymin.weixin.entity.freight.TruckType;
import com.easymin.weixin.entity.passenger.Passenger;
import com.easymin.weixin.entity.sales.ActivityManage;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.*;

@Component
public class DaijiaApi {

    private static final Logger logger = LoggerFactory.getLogger(DaijiaApi.class);

    @Autowired
    private RestTemplate restTemplate;
    /**
     * 发送验证码.
     */
    private static final String SEND_CODE = "api/sms/send?phone={phone}";

    /**
     * 发送验证码升级版，使用图片验证码机制.
     */
    private static final String SEND_CODE_UP = "api/sms/sendup?IP={IP}&phone={phone}&imageCode={imageCode}";

    /**
     * 发送验证码升级v2版，必须使用图片验证码才能发送短信.
     */
    private static final String SEND_CODE_UP_V2 = "api/sms/sendupv2?IP={IP}&phone={phone}&imageCode={imageCode}";

    /**
     * 检查验证码.
     */
    public static final String CHECK_CODE = "api/sms/check?phone={phone}&vcode={vcode}";

    /**
     * 检查验证码.
     */
    public static final String CHECK_CODE_V5 = "api/sms/check?IP={IP}&phone={phone}&vcode={vcode}";

    /**
     * 获取设置服务.
     */
    public static final String GET_SERVICE = "api/system/getService";

    /**
     * 查询支付设置
     */
    public static final String GET_PAY_SETTING_V5 = "api/system/queryPaySetting";

    /**
     * 代驾附近司机.
     */
    public static final String QUERY_NEAR_DRIVER = "api/daijia/queryNearDriver?longitude={longitude}&latitude={latitude}&distance={distance}";
    /**
     * 代驾计费.
     */
    public static final String GET_PRICE = "api/daijia/getPrice?ack={ack}&passengerId={passengerId}&startLat={startLat}"
            + "&startLng={startLng}&endLat={endLat}&endLng={endLng}";
    /**
     * 微信下单.
     */
    public static final String CREATE_ORDER_FORM_WEIXIN = "api/daijia/createWeixin?ack={ack}&beginAddress={beginAddress}"
            + "&beginAddressDetail={beginAddressDetail}&beginLat={beginLat}&beginLng={beginLng}"
            + "&endAddress={endAddress}&endAddressDetail={endAddressDetail}&endLat={endLat}"
            + "&endLng={endLng}&phone={phone}&money={money}&openId={openId}";
    /**
     * 根据城市查询公司信息.
     */
    public static final String FIND_COMPANY_BY_CITY = "api/company/findByCity?city={city}";
    /**
     * 查询AppSetting.
     */
    public static final String APP_SETTING = "api/system/getAppSetting";

    /**
     * 查询AppSetting.
     */
    public static final String APP_SETTING_V5 = "api/system/getAppSetting";

    /**
     * 工作车下单推送到代驾项目.
     */
    public static final String SIMPLECARPOOL = "api/simplecarpool/push?drivers={drivers}&employId={employId}";

    /**
     * 销单推送.
     */
    public static final String SIMPLECARPOOL_PUSHCANCEL = "api/simplecarpool/pushCancel?drivers={drivers}&employName={employName}";

    /**
     * 专车附近司机.
     */
    public static final String QUERY_ZC_NEAR_DRIVER = "api/zhuanche/queryNearDriver?longitude={longitude}"
            + "&latitude={latitude}&carTypeId={carTypeId}";
    /**
     * 专车类型.
     */
    public static final String GET_CARTYPE = "api/zhuanche/getCarType?ack={ack}&passengerId={passengerId}"
            + "&longitude={longitude}&latitude={latitude}";

    public static final String FIND_CARTYPE = "api/zhuanche/findCarType?ack={ack}&passengerId={passengerId}"
            + "&carTypeId={carTypeId}&longitude={longitude}&latitude={latitude}";
    /**
     * 专车计费.
     */
    public static final String GET_PRICE_BY_CARTYPE = "api/zhuanche/getPriceByCarType?carTypeId={carTypeId}&startLat={startLat}"
            + "&startLng={startLng}&endLat={endLat}&endLng={endLng}";
    /**
     * 预算价格V4.
     */
    public static final String GET_PRICEV4 = "api/errand/getPriceByAreaId?areaId={areaId}&startLat={startLat}"
            + "&startLng={startLng}&endLat={endLat}&endLng={endLng}";
    /**
     * 微信下单.
     */
    public static final String CREATE_ZC_FROM_WEIXIN = "api/zhuanche/createWeixin?ack={ack}&beginAddress={beginAddress}"
            + "&beginAddressDetail={beginAddressDetail}&beginLat={beginLat}&beginLng={beginLng}"
            + "&endAddress={endAddress}&endAddressDetail={endAddressDetail}&endLat={endLat}"
            + "&endLng={endLng}&phone={phone}&openId={openId}&carTypeId={carTypeId}";
    /**
     * 代驾销单. POST.
     */
    public static final String CANCEL_DAIJIA_ORDER = "api/daijia/cancel?orderId={orderId}&cause={cause}";
    /**
     * 获取客户端分享二维码所需数据.
     */
    public static final String GET_QRCODEDATA = "api/passenger/getQrCodeData?passengerId={passengerId}&acKey={acKey}";
    /**
     * 查询司机. GET.
     */
    public static final String QUERY_ONE_DRIVER = "api/daijia/queryDriver?driverId={driverId}";
    /**
     * 查询司机位置信息.
     */
    public static final String QUERY_DRIVER_ADDRESS = "api/simplecarpool/queryDriver?driverId={driverId}";
    /**
     * 查询代驾订单. GET.
     */
    public static final String QUERY_ONE_DAIJIA_ORDER = "api/daijia/findOne?orderId={orderId}";

    /**
     * 查询代驾订单. GET.
     */
    public static final String QUERY_ONE_DAIJIA_ORDER_V5 = "api/daijia/findOneV5?orderId={orderId}";

    /**
     * 专车销单. POST.
     */
    public static final String CANCEL_ZHUANCHE_ORDER = "api/zhuanche/cancel?orderId={orderId}&cause={cause}";
    /**
     * 查询专车订单. GET.
     */
    public static final String QUERY_ONE_ZHUANCHE_ORDER = "api/zhuanche/findOne?orderId={orderId}";
    /**
     * 预算跑腿价格.
     */
    public static final String GET_ERRAND_PRICE = "api/errand/getPrice?passengerId={passengerId}&city={city}&acKey={acKey}&startLat={startLat}"
            + "&startLng={startLng}&endLat={endLat}&endLng={endLng}";
    /**
     * 获取公司ID.
     */
    public static final String GET_ERRAND_NEW_PRICE = "api/errand/getNewPrice?passengerId={passengerId}&city={city}&acKey={acKey}"
            + "&time={time}&mileage={mileage}";
    /**
     * 预算价格(根据areaId,经纬度).
     */
    public static final String GET_PRICE_BY_AREAID = "api/errand/getPriceByAreaId?areaId={areaId}&startLat={startLat}&startLng={startLng}";
    /**
     * 获取代驾预支付Id.
     */
    public static final String GET_DJ_WX_PREPAYID = "api/daijia/wx/prepayId_jsapi.json?orderId={orderId}&openid={openid}";
    /**
     * 获取专车预支付Id.
     */
    public static final String GET_ZC_WX_PREPAYID = "api/zhuanche/wx/prepayId_jsapi.json?orderId={orderId}&openid={openid}";

    public static final String GET_PT_WX_PREPAYID = "api/errand/wx/prepayId_jsapi.json?orderId={orderId}&openid={openid}";
    /**
     * 获取收费标准.
     */
    private static final String QUERY_AREA = "api/daijia/queryArea.json?areaId={areaId}";
    /**
     * 获取收费标准V4.
     */
    private static final String QUERY_CHARGESTARTTIMES = "api/company/v4/findChargeStartTimes.json?areaId={areaId}";
    /**
     * 查询司机V4.
     */
    public static final String QUERY_ONE_DRIVER_V4 = "api/employ/v4/findEmploy?employId={employId}";
    /**
     * app查询司机V4根据token.
     */
    public static final String QUERY_ONE_DRIVER_V4_TOKEN = "api/employ/v4/findEmployByToken?employToken={employToken}";
    /**
     * 查询活动.
     */
    public static final String QUERY_ACTIVITY = "api/activitymanage/queryActivityManages?longitude={longitude}"
            + "&latitude={latitude}&acKey={acKey}&page={page}&limit={limit}";

    public static final String QUERY_ACTIVITY_BY_SERVICE = "api/activitymanage/indexActivityManages?longitude={longitude}"
            + "&latitude={latitude}&acKey={acKey}&serviceType={serviceType}";
    /**
     * 获取公司.
     */
    public static final String GET_COMPANY = "member/api/rest/v3/getCompany";
    /**
     * 获取公司ID和名称.
     */
    public static final String GET_COMPANYIDANDNAME = "member/api/rest/v3/getCompanyIdAndName";
    /**
     * 获取公司收费标准.
     */
    public static final String GET_COMPANYBYAREA = "member/api/rest/v3/getCompanyByArea";
    /**
     * 查询附近跑腿服务人员.
     */
    public static final String QUERY_ERRAND_DRIVER = "api/errand/queryErrandDriver?lng={lng}&lat={lat}";
    /**
     * 专车销单V4.
     */
    public static final String CANCEL_ZHUANCHE_ORDER_V4 = "api/zhuanche/v4/cancel?orderId={orderId}&cause={cause}";
    /**
     * V4根据areaId,经纬度预估费用.
     */
    public static final String GET_PRICE_BY_AREAID_V4 = "api/errand/v4/getPriceByAreaId?areaId={areaId}&startLat={startLat}&startLng={startLng}";
    /**
     * V4根据areaId,时间,距离预算费用.
     */
    public static final String GET_PRICE_BY_TIME_MILEAGE_V4 = "api/errand/v4/getPriceByTimeAndMileage?areaId={areaId}&time={time}&mileage={mileage}&weight={weight}";
    /**
     * V4工作车下单推送到代驾项目.
     */
    public static final String SIMPLECARPOOL_V4 = "api/simplecarpool/v4/push?drivers={drivers}&employId={employId}";
    /**
     * V4工作车销单推送.
     */
    public static final String SIMPLECARPOOL_PUSHCANCEL_V4 = "api/simplecarpool/v4/pushCancel?drivers={drivers}&employName={employName}";
    /**
     * 查询未支付订单.
     */
    public static final String COUNT_NOTPAYAMOUNTS = "api/daijia/countNotPayAmounts?passengerId={passengerId}";

    public static final String FIND_RUNNING = "api/daijia/findRunning?passengerId={passengerId}";

    public static final String FIND_RUNNING_V5 = "api/daijia/findRunningv5?passengerId={passengerId}";

    /**
     * 微信广告.
     */
    public static final String ADVERTISEMENT = "api/daijia/advertisement?companyId={companyId}";

    /**
     * v5微信广告
     */

    public static final String GET_WEIXIN_V5_NEWS = "api/news/weixin?companyId={companyId}&serviceType={serviceType}";

    /**
     * 根据经纬度查询公司.
     */
    // public static final String GET_COMPANYBYLATLNG =
    // "member/api/rest/v3/getCompanyIdAndName.json?longitude={longitude}&latitude={latitude}";

    /**
     * 跑腿下单 余额、签单支付时 检查是否满足条件
     */
    public static final String BALANCESIGNPAY_CHECK = "api/errand/balancesignPayCheck?money={money}&passengerId={passengerId}&payType={payType}";

    /**
     * 跑腿预支付 财务记录
     */
    public static final String ORDER_PAY = "api/errand/orderPay?orderId={orderId}";

    /**
     * 更新客户信息接口V5
     */
    public static final String UPDATE_PASSENGER_V5 = "api/passenger/wxV5updatePassenger";

    /**
     * 微信V5获取订单信息
     */
    public static final String GET_ORDERS_V5 = "api/daijia/findOrdersV5";

    /**
     * 获取司机信息
     */
    public static final String GET_ZHUAN_DRIVER = "api/zhuanche/getZhuanEmploy?id={id}";

    /**
     * 获取司机信息
     */
    public static final String GET_WX_QRCODE = "api/zhuanche/getWxQrCode";
    /**
     * V4确认费用重量预算费用.
     */
    public static final String GET_PRICE_BY_WEIGHT_V4 = "api/errand/v4/getErrandWeightPrice?orderId={orderId}&weight={weight}&mileage= {mileage}";


    /**
     * 查询活动.
     */
    public Map<String, Object> queryActivity(String server, Double longitude, Double latitude, Long passengerId,
                                             String acKey, Integer page, Integer limit) {
        Map<String, Object> map = new HashMap<String, Object>();
        String result = restTemplate.postForObject(buildApi(server, QUERY_ACTIVITY), null, String.class, longitude,
                latitude, acKey, page, limit);
        JSONObject object = JSON.parseObject(result);
        Boolean success = object.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("msg", "查询成功");
            JSONObject data = object.getJSONObject("data");

            Long total = data.getLong("totalElements");
            JSONArray jsonArray = data.getJSONArray("content");

            List<ActivityManage> list = JSON.parseArray(jsonArray.toString(), ActivityManage.class);
            Map<String, Object> dataMap = new HashMap<String, Object>();
            dataMap.put("total", total);
            dataMap.put("content", list);
            map.put("data", dataMap);
        } else {
            map.put("code", -1);
            map.put("msg", "查询失败");
        }
        return map;
    }

    /**
     * 根据业务分类查询活动.
     *
     * @param serviceType daijia,zhuanche...
     */

    public Map<String, Object> queryActivityByService(String server, Double longitude, Double latitude,
                                                      Long passengerId, String acKey, String serviceType) {
        Map<String, Object> map = new HashMap<String, Object>();
        String result = restTemplate.postForObject(buildApi(server, QUERY_ACTIVITY_BY_SERVICE), null, String.class,
                longitude, latitude, acKey, serviceType);
        JSONObject object = JSON.parseObject(result);
        Boolean success = object.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("msg", "查询成功");
            JSONArray jsonArray = object.getJSONArray("data");

            List<ActivityManage> list = JSON.parseArray(jsonArray.toString(), ActivityManage.class);
            Map<String, Object> dataMap = new HashMap<String, Object>();
            dataMap.put("content", list);
            map.put("data", dataMap);
        } else {
            map.put("code", -1);
            map.put("msg", "查询失败");
        }
        return map;
    }

    /**
     * 查询系统开启的服务.
     *
     * @param server 服务器地址
     */

    public JSONObject getServices(String server) {
        String response = restTemplate.getForObject(buildApi(server, GET_SERVICE), String.class);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 查询司机信息 包含位置.
     */

    public JSONObject findDriver(String server, long driverId) {

        String response = restTemplate.getForObject(buildApi(server, QUERY_ONE_DRIVER), String.class, driverId);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 查询代驾订单.
     */

    public JSONObject findOrder(String server, long orderId) {

        String response = restTemplate.getForObject(buildApi(server, QUERY_ONE_DAIJIA_ORDER), String.class, orderId);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 微信V5查询单个订单
     *
     * @param server
     * @param orderId
     * @return
     */
    public JSONObject findOrderV5(String server, long orderId) {

        String response = restTemplate.getForObject(buildApi(server, QUERY_ONE_DAIJIA_ORDER_V5), String.class, orderId);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 预算代驾费用.
     *
     * @param server      服务器地址
     * @param ack         指定公司key 可选
     * @param passengerId 乘客Id 可选
     * @param startLat    开始纬度
     * @param startLng    开始经度
     * @param endLat      结束纬度
     * @param endLng      结束经度
     */
    public JSONObject calculationPrice(String server, String ack, Long passengerId, Double startLat, Double startLng,
                                       Double endLat, Double endLng) {
        String response = restTemplate.getForObject(buildApi(server, GET_PRICE), String.class, ack, passengerId,
                startLat, startLng, endLat, endLng);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 查询附近司机.
     *
     * @param server    服务器地址
     * @param longitude 经度
     * @param latitude  维度
     * @param distance  范围
     */
    public JSONObject countNearDriver(String server, double longitude, double latitude, double distance) {
        String response = restTemplate.getForObject(buildApi(server, QUERY_NEAR_DRIVER), String.class, longitude,
                latitude, distance);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 发送验证码短信.
     *
     * @param server 服务器地址
     * @param phone  手机号码
     * @return
     */
    public String sendVcode(String server, String phone) {

        String response = restTemplate.getForObject(buildApi(server, SEND_CODE), String.class, phone);
        return response;
    }

    /**
     * 发送验证码短信升级版本，使用图片验证码机制.
     *
     * @param server    服务器地址
     * @param ip        用户IP
     * @param phone     手机号码
     * @param imageCode 图片验证码
     * @return
     */
    public String sendVcodeUp(String server, String ip, String phone, String imageCode) {

        String response = restTemplate.getForObject(buildApi(server, SEND_CODE_UP), String.class, ip, phone, imageCode);
        return response;
    }

    /**
     * 发送验证码短信升级v2版本，必须使用图片验证码才能发送.
     *
     * @param server    服务器地址
     * @param ip        用户IP
     * @param phone     手机号码
     * @param imageCode 图片验证码
     * @return
     */
    public String sendVcodeUpV2(String server, String ip, String phone, String imageCode) {

        String response = restTemplate.getForObject(buildApi(server, SEND_CODE_UP_V2), String.class, ip, phone,
                imageCode);
        return response;
    }

    /**
     * 验证验证码是否正确.
     */
    public String validateCode(String server, String phone, String vcode) {

        String response = restTemplate.getForObject(buildApi(server, CHECK_CODE), String.class, phone, vcode);

        return response;
    }

    /**
     * 验证验证码是否正确.
     */
    public String validateCodeV5(String server, String IP, String phone, String vcode) {

        String response = restTemplate.getForObject(buildApi(server, CHECK_CODE_V5), String.class, IP, phone, vcode);

        return response;
    }

    /**
     * 预约代驾订单.
     *
     * @param server       服务器地址
     * @param ack          指定公司
     * @param beginAddress 预约地址
     * @param endAddress   目的地址
     * @param phone        手机号
     * @param openId       微信号 可选
     */
    public String makeAnAppointment(String server, String ack, String beginAddress, String beginAddressDetail,
                                    Double beginLat, Double beginLng, String endAddress, String endAddressDetail, Double endLat, Double endLng,
                                    String phone, String openId) {
        Map<String, Object> params = new HashMap<>();
        params.put("ack", ack);
        params.put("beginAddress", beginAddress);
        params.put("beginAddressDetail", beginAddressDetail);
        params.put("beginLat", beginLat);
        params.put("beginLng", beginLng);
        params.put("endAddress", endAddress);
        params.put("endAddressDetail", endAddressDetail);
        params.put("endLat", endLat);
        params.put("endLng", endLng);
        params.put("phone", phone);
        params.put("money", 0);
        params.put("openId", openId);

        String response = restTemplate.postForObject(buildApi(server, CREATE_ORDER_FORM_WEIXIN), null, String.class,
                params);

        return response;
    }

    /**
     * 微信下代驾订单.
     */

    public String makeAnAppointmentV4(String server, String ack, String beginAddress, String beginAddressDetail,
                                      Double beginLat, Double beginLng, String endAddress, String endAddressDetail, Double endLat, Double endLng,
                                      String phone, BigDecimal money, String openId) {
        Map<String, Object> params = new HashMap<>();
        params.put("ack", ack);
        params.put("beginAddress", beginAddress);
        params.put("beginAddressDetail", beginAddressDetail);
        params.put("beginLat", beginLat);
        params.put("beginLng", beginLng);
        params.put("endAddress", endAddress);
        params.put("endAddressDetail", endAddressDetail);
        params.put("endLat", endLat);
        params.put("endLng", endLng);
        params.put("phone", phone);
        params.put("money", money);
        params.put("openId", openId);

        String response = restTemplate.postForObject(buildApi(server, CREATE_ORDER_FORM_WEIXIN), null, String.class,
                params);

        return response;
    }

    /**
     * 获取代驾微信预支付.
     */
    public JSONObject getDjWxPrepayId(String server, Long orderId, String openid) {

        String response = restTemplate.getForObject(buildApi(server, GET_DJ_WX_PREPAYID), String.class, orderId,
                openid);

        return JSON.parseObject(response);
    }

    /**
     * 根据城市查询公司信息.
     */
    public String findCompany(String server, String city) {
        String response = restTemplate.getForObject(buildApi(server, FIND_COMPANY_BY_CITY), String.class, city);

        return response;
    }

    /**
     * 查询系统的设置.
     */
    public String findErrandSetting(String server) {

        String response = restTemplate.getForObject(buildApi(server, APP_SETTING), String.class);

        return response;
    }

    /**
     * 工作车下单推送到代驾项目.
     */
    public String simplecarpool(String server, Long[] drivers, Long employId) {
        Map<String, String> map = new HashMap<String, String>();
        String string = ArrayUtils.toString(drivers);
        map.put("drivers", string.toString().replace("{", "").replace("}", ""));
        map.put("employId", String.valueOf(employId));
        String response = restTemplate.postForObject(buildApi(server, SIMPLECARPOOL), null, String.class, map);
        return response;
    }

    /**
     * 工作车下单推送.
     */

    public ResultTransport simplecarpoolV4(String server, String drivers, Long employId) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("drivers", drivers);
        map.put("employId", String.valueOf(employId));
        String result = restTemplate.postForObject(buildApi(server, SIMPLECARPOOL_V4), null, String.class, map);
        return JSON.parseObject(result, ResultTransport.class);
    }

    /**
     * 工作车销单推送到代驾项目.
     */

    public String simplecarpoolCancel(String server, Long[] drivers, String employName) {
        Map<String, String> map = new HashMap<String, String>();
        String string = ArrayUtils.toString(drivers);
        map.put("drivers", string.toString().replace("{", "").replace("}", ""));
        map.put("employName", employName);
        String response = restTemplate.postForObject(buildApi(server, SIMPLECARPOOL_PUSHCANCEL), null, String.class,
                map);
        return response;
    }

    /**
     * 工作车销单推送.
     */

    public ResultTransport simplecarpoolCancelV4(String server, String drivers, String employName) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("drivers", drivers);
        map.put("employName", employName);
        String result = restTemplate.postForObject(buildApi(server, SIMPLECARPOOL_PUSHCANCEL_V4), null, String.class,
                map);

        return JSON.parseObject(result, ResultTransport.class);
    }

    /**
     * 查询司机位置信息.
     */

    public JSONObject queryDriverAddress(String server, long driverId) {

        String response = restTemplate.getForObject(buildApi(server, QUERY_DRIVER_ADDRESS), String.class, driverId);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 催促跑腿订单进度.
     */

    public String hastenOrder(String server, Long orderId) {

        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/errand/hurryOrder"));
        builder.append("?orderId={orderId}");
        String response = restTemplate.getForObject(builder.toString(), String.class, orderId);

        return response;
    }

    /**
     * 催促代驾订单进度.
     */
    public Map<String, Object> hastenDaijiaOrder(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/hurryOrder?orderId={orderId}"));
        String response = restTemplate.getForObject(builder.toString(), String.class, orderId);

        JSONObject jsonObject = JSON.parseObject(response);

        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("msg", "催单成功");
            map.put("data", null);
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
        }

        return map;
    }

    /**
     * 代驾订单销单.
     */
    public Map<String, Object> cancel(String address, Long orderId, String cause) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, CANCEL_DAIJIA_ORDER));
        Map<String, Object> kv = new HashMap<>();
        kv.put("orderId", orderId);
        kv.put("cause", cause);
        String result = restTemplate.postForObject(builder.toString(), null, String.class, kv);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("msg", "销单成功");
            map.put("data", null);
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 获取客户端分享二维码所需数据.
     */
    public Map<String, Object> getQrCodeData(String address, Long passengerId, String acKey) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, GET_QRCODEDATA));
        Map<String, Object> kv = new HashMap<>();
        kv.put("passengerId", passengerId);
        kv.put("acKey", acKey);
        String result = restTemplate.postForObject(builder.toString(), null, String.class, kv);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("msg", "获取客户端分享二维码所需数据");
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("shareUrl", jsonObject.getString("shareUrl"));
            data.put("qrLogo", jsonObject.getString("qrLogo"));
            data.put("description", jsonObject.getString("description"));
            map.put("data", data);
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 评价代驾订单.
     */
    public Map<String, Object> review(String address, String phone, Long driverId, Long orderId, Double score,
                                      @RequestParam(value = "content", required = false) String content) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/review?phone={phone}&driverId={driverId}"
                + "&orderId={orderId}&score={score}&content={content}"));
        Map<String, Object> kv = new HashMap<>();
        kv.put("phone", phone);
        kv.put("driverId", driverId);
        kv.put("orderId", orderId);
        kv.put("score", score);
        kv.put("content", content);
        String result = restTemplate.postForObject(builder.toString(), null, String.class, kv);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("msg", "评价成功");
            map.put("data", null);
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 微信V5获取代驾评价
     */
    private static final String GET_REVIEW_V5 = "api/daijia/getReview?passengerId={passengerId}&orderId={orderId}";

    /**
     * 微信V5获取代驾评价
     *
     * @param server      代驾地址
     * @param passengerId 乘客ID
     * @param orderId     订单ID
     * @return
     */
    public ResultV5 getReview(String server, Long passengerId, Long orderId) {
        String rs = restTemplate.getForObject(buildApi(server, GET_REVIEW_V5), String.class, passengerId, orderId);
        JSONObject json = JSONObject.parseObject(rs);
        ResultV5 result = null;
        if (json.getBooleanValue("success")) {
            result = ErrorMapV5.ERR_SUCCESS.clone();
            result.setData(json.getJSONObject("data"));
        } else {
            result = ErrorMapV5.ERR_GET_DAIJIA_REVIEW;
        }
        return result;
    }

    /**
     * 查询司机是否忙碌.
     *
     * @param driverId success:true/false 访问失败:false status:0:未上班,1:空闲(在线),2:接单,3:忙碌
     *                 jobStatus:0代驾 1专车 2跑腿 -1无任务
     * @return true可以接单, false不可以接单
     */
    public boolean findEmployStatus(String server, Long driverId) {
        boolean bool = false;
        try {

            StringBuilder builder = new StringBuilder();
            builder.append(buildApi(server, "api/errand/getEmployStatus"));
            builder.append("?driverId={driverId}");
            String response = restTemplate.getForObject(builder.toString(), String.class, driverId);

            JSONObject jsonObject = JSON.parseObject(response);

            boolean success = jsonObject.getBoolean("success");
            if (success == true) {
                int status = jsonObject.getIntValue("status"); // 工作状态
                int jobStatus = jsonObject.getIntValue("jobStatus"); // 执行类型
                if (jobStatus == 2 && status != 0) { // 跑腿类型的工作
                    bool = true;
                } else if (jobStatus == -1) { // 无任务
                    if (status != 0) {
                        bool = true;
                    }
                }
            }
        } catch (Exception ex) {
            logger.error("daijiaApi", ex.getMessage());
        }
        return bool;
    }

    /**
     * 调创建新客户的活动.
     */

    public void newPassengerActivity(String server, Long id) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", id);
        try {
            restTemplate.postForObject(buildApi(server, "api/activity/newPassengerActivity?id={id}"), null,
                    String.class, map);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
        }
    }

    /**
     * 新客户参与活动.
     */

    public void newPassengerActivityV4(String server, Long passengerId) {
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("passengerId", passengerId);
            restTemplate.postForObject(
                    buildApi(server, "api/activity/v4/newPassengerActivity?passengerId={passengerId}"), null,
                    String.class, map);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
        }
    }

    /**
     * 创建代驾订单.
     */
    public Map<String, Object> create(String address, Long passengerId, String passengerName, String passengerPhone,
                                      String userPhone, Long companyId, String channelName, String startAddress, String startAddressDetail,
                                      Double startLat, Double startLng, String endAddress, String endAddressDetail, Double endLat, Double endLng,
                                      Long serverTime, Double budgetPay, Long couponId, String orderNoRenBao, String cuponNoRenBao, String preferentialType) {

        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address,
                "api/daijia/create.json?clientId={clientId}&clientName={clientName}"
                        + "&clientPhone={clientPhone}&userPhone={userPhone}&companyId={companyId}"
                        + "&fromSource={fromSource}&startAddress={startAddress}"
                        + "&startLat={startLat}&startLng={startLng}&serverTime={serverTime}"));

        try {
            Map<String, Object> kv = new HashMap<>();
            kv.put("clientId", passengerId);
            if (StringUtils.isBlank(passengerName)) {
                passengerName = "先生/女士";
            }
            kv.put("clientName", passengerName);
            kv.put("clientPhone", passengerPhone);
            kv.put("userPhone", userPhone);
            kv.put("companyId", companyId);
            kv.put("fromSource", channelName);
            if (StringUtils.isNotBlank(startAddressDetail)) {
                startAddress += startAddressDetail;
            }
            kv.put("startAddress", startAddress);
            kv.put("startLat", startLat);
            kv.put("startLng", startLng);
            if (StringUtils.isNotBlank(endAddressDetail)) {
                endAddress += endAddressDetail;
            }
            if (StringUtils.isNotBlank(endAddress)) {
                kv.put("endAddress", endAddress);
                builder.append("&endAddress={endAddress}");
            }

            if (StringUtils.isNotBlank(orderNoRenBao)) {
                kv.put("orderNoRenBao", orderNoRenBao);
                builder.append("&orderNoRenBao={orderNoRenBao}");
            }
            if (StringUtils.isNotBlank(cuponNoRenBao)) {
                kv.put("cuponNoRenBao", cuponNoRenBao);
                builder.append("&cuponNoRenBao={cuponNoRenBao}");
            }
            if (StringUtils.isNotBlank(preferentialType)) {
                kv.put("preferentialType", preferentialType);
                builder.append("&preferentialType={preferentialType}");
            }

            if (endLat != null) {
                kv.put("endLat", endLat);
                builder.append("&endLat={endLat}");
            }
            if (endLng != null) {
                kv.put("endLng", endLng);
                builder.append("&endLng={endLng}");
            }
            kv.put("serverTime", serverTime);
            if (budgetPay != null) {
                kv.put("fixPriceMoney", budgetPay);
                builder.append("&fixPriceMoney={fixPriceMoney}");
            }
            if (couponId != null && couponId != 0) {
                kv.put("couponId", couponId);
                builder.append("&couponId={couponId}");
            }
            String result = restTemplate.postForObject(builder.toString(), null, String.class, kv);

            JSONObject jsonObject = JSON.parseObject(result);

            Boolean success = jsonObject.getBoolean("success");
            if (success) {
                map.put("code", 0);
                map.put("msg", "下单成功");
                Map<String, Object> data = new HashMap<String, Object>();
                Long orderId = jsonObject.getLong("orderId");
                Boolean prePay = jsonObject.getBoolean("prePay");
                Boolean overdraw = jsonObject.getBoolean("overdraw");
                BigDecimal budgetPay1 = jsonObject.getBigDecimal("budgetPay");
                data.put("orderId", orderId);
                data.put("prePay", prePay);
                data.put("overdraw", overdraw);

                if (prePay) {
                    Map<String, Object> map2 = queryPaySetting(address);
                    Boolean weixinPay = (Boolean) map2.get("weixinPay");
                    Boolean aliPay = (Boolean) map2.get("aliPay");
                    try {
                        Boolean unionPay = (Boolean) map2.get("unionPay");
                        data.put("unionPay", unionPay);
                    } catch (Exception e) {
                        data.put("unionPay", false);
                    }
                    try {
                        Boolean bestPay = (Boolean) map2.get("bestPay");
                        data.put("bestPay", bestPay);
                    } catch (Exception e) {
                        data.put("bestPay", false);
                    }
                    data.put("weixinPay", weixinPay);
                    data.put("aliPay", aliPay);
                }
                data.put("budgetPay", budgetPay1);
                map.put("data", data);
            } else {
                try {
                    int code = jsonObject.getIntValue("code");
                    map.put("code", code);
                } catch (Exception ex) {
                    map.put("code", -1);
                }
                map.put("msg", jsonObject.getString("message"));
            }
            return map;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 创建人保代驾订单.
     * 人保数据中会少掉一些字段，所以将参数全部设置为允许为空
     */
    public Map<String, Object> createRenBao(@RequestParam(required = false, value = "address") String address, @RequestParam(required = false, value = "passengerId") Long passengerId,
                                            @RequestParam(required = false, value = "passengerName") String passengerName, @RequestParam(required = false, value = "passengerPhone") String passengerPhone,
                                            @RequestParam(required = false, value = "userPhone") String userPhone,
                                            @RequestParam(required = false, value = "companyId") Long companyId, @RequestParam(required = false, value = "channelName") String channelName,
                                            @RequestParam(required = false, value = "startAddress") String startAddress, @RequestParam(required = false, value = "startAddressDetail") String startAddressDetail,
                                            @RequestParam(required = false, value = "startLat") Double startLat, @RequestParam(required = false, value = "startLng") Double startLng,
                                            @RequestParam(required = false, value = "endAddress") String endAddress, @RequestParam(required = false, value = "endAddressDetail") String endAddressDetail,
                                            @RequestParam(required = false, value = "endLat") Double endLat, @RequestParam(required = false, value = "endLng") Double endLng,
                                            @RequestParam(required = false, value = "serverTime") Long serverTime, @RequestParam(required = false, value = "budgetPay") Double budgetPay,
                                            @RequestParam(required = false, value = "couponId") Long couponId,
                                            @RequestParam(required = false, value = "orderNoRenBao") String orderNoRenBao, @RequestParam(required = false, value = "cuponNoRenBao") String cuponNoRenBao,
                                            @RequestParam(required = false, value = "preferentialType") String preferentialType, @RequestParam(required = false, value = "passengerType") String passengerType) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address,
                "api/daijia/createRenBao.json?clientId={clientId}&clientName={clientName}"
                        + "&clientPhone={clientPhone}&userPhone={userPhone}&companyId={companyId}"
                        + "&fromSource={fromSource}&startAddress={startAddress}"
                        + "&startLat={startLat}&startLng={startLng}&serverTime={serverTime}"));

        try {
            Map<String, Object> kv = new HashMap<>();
            kv.put("clientId", passengerId);
            if (StringUtils.isBlank(passengerName)) {
                passengerName = "先生/女士";
            }
            kv.put("clientName", passengerName);
            kv.put("clientPhone", passengerPhone);
            //判断是否为人保客户
            if (orderNoRenBao.isEmpty() || cuponNoRenBao.isEmpty()) {
                kv.put("userPhone", userPhone);
            } else {
                kv.put("userPhone", passengerPhone);
            }
            kv.put("companyId", companyId);
            kv.put("fromSource", channelName);
            if (StringUtils.isNotBlank(startAddressDetail)) {
                startAddress += startAddressDetail;
            }
            kv.put("startAddress", startAddress);
            kv.put("startLat", startLat);
            kv.put("startLng", startLng);
            if (StringUtils.isNotBlank(endAddressDetail)) {
                endAddress += endAddressDetail;
            }
            if (StringUtils.isNotBlank(endAddress)) {
                kv.put("endAddress", endAddress);
                builder.append("&endAddress={endAddress}");
            }

            if (StringUtils.isNotBlank(orderNoRenBao)) {
                kv.put("orderNoRenBao", orderNoRenBao);
                builder.append("&orderNoRenBao={orderNoRenBao}");
            }
            if (StringUtils.isNotBlank(cuponNoRenBao)) {
                kv.put("cuponNoRenBao", cuponNoRenBao);
                builder.append("&cuponNoRenBao={cuponNoRenBao}");
            }
            if (StringUtils.isNotBlank(preferentialType)) {
                kv.put("preferentialType", preferentialType);
                builder.append("&preferentialType={preferentialType}");
            }
            if (endLat != null) {
                kv.put("endLat", endLat);
                builder.append("&endLat={endLat}");
            }
            if (endLng != null) {
                kv.put("endLng", endLng);
                builder.append("&endLng={endLng}");
            }
            //人保用户判断
            if (StringUtils.isNotBlank(orderNoRenBao) || StringUtils.isNotBlank(cuponNoRenBao)) {
                kv.put("serverTime", serverTime);
            } else {
                serverTime = System.currentTimeMillis();
                kv.put("serverTime", serverTime);
            }

            if (budgetPay != null) {
                BigDecimal bigDecimal = BigDecimal.valueOf(budgetPay);
                kv.put("fixPriceMoney", budgetPay);
                builder.append("&fixPriceMoney={fixPriceMoney}");
            }
            if (couponId != null && couponId != 0) {
                kv.put("couponId", couponId);
                builder.append("&couponId={couponId}");
            }
            if (passengerType != null) {
                kv.put("passengerType", passengerType);
                builder.append("&passengerType={passengerType}");
            }
            String result = restTemplate.postForObject(builder.toString(), null, String.class, kv);

            JSONObject jsonObject = JSON.parseObject(result);

            Boolean success = jsonObject.getBoolean("success");
            if (success) {
                map.put("code", 0);
                map.put("msg", "下单成功");
                Map<String, Object> data = new HashMap<String, Object>();
                Long orderId = jsonObject.getLong("orderId");
                Boolean prePay = jsonObject.getBoolean("prePay");
                Boolean overdraw = jsonObject.getBoolean("overdraw");
                BigDecimal budgetPay1 = jsonObject.getBigDecimal("budgetPay");
                data.put("orderId", orderId);
                data.put("prePay", prePay);
                data.put("overdraw", overdraw);

                if (prePay) {
                    Map<String, Object> map2 = queryPaySetting(address);
                    Boolean weixinPay = (Boolean) map2.get("weixinPay");
                    Boolean aliPay = (Boolean) map2.get("aliPay");
                    try {
                        Boolean unionPay = (Boolean) map2.get("unionPay");
                        data.put("unionPay", unionPay);
                    } catch (Exception e) {
                        data.put("unionPay", false);
                    }
                    try {
                        Boolean bestPay = (Boolean) map2.get("bestPay");
                        data.put("bestPay", bestPay);
                    } catch (Exception e) {
                        data.put("bestPay", false);
                    }
                    data.put("weixinPay", weixinPay);
                    data.put("aliPay", aliPay);
                }
                data.put("budgetPay", budgetPay1);
                map.put("data", data);
            } else {
                try {
                    int code = jsonObject.getIntValue("code");
                    map.put("code", code);
                } catch (Exception ex) {
                    map.put("code", -1);
                }
                map.put("msg", jsonObject.getString("message"));
            }
            return map;
        } catch (Exception e) {
            e.printStackTrace();
            map.put("code", -199);
            map.put("msg", "创建人保订单错误");
            return map;
        }
    }

    /**
     * 代驾订单预算价格.
     */
    public Map<String, Object> getDaijiaPrice(String address, Long passengerId, Double startLat, Double startLng,
                                              Double endLat, Double endLng) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/getPrice.json?startLat={startLat}"
                + "&startLng={startLng}&endLat={endLat}&endLng={endLng}"));
        String result = "";
        if (passengerId != null && passengerId != 0) {
            builder.append("&passengerId={passengerId}");
            result = restTemplate.getForObject(builder.toString(), String.class, startLat, startLng, endLat, endLng,
                    passengerId);
        } else {
            result = restTemplate.getForObject(builder.toString(), String.class, startLat, startLng, endLat, endLng);
        }

        JSONObject jsonObject = JSON.parseObject(result);

        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Double money = jsonObject.getDouble("money");
            Double mileage = jsonObject.getDouble("mileage");
            Double startPrice = jsonObject.getDouble("startPrice");
            Double mileagePrice = jsonObject.getDouble("mileagePrice");
            Double travelTimePrice = jsonObject.getDouble("travelTimePrice");
            Long travelTime = jsonObject.getLong("travelTime");
            String payDetail = jsonObject.getString("pay_detail");
            map.put("success", true);
            map.put("money", money);
            map.put("startPrice", startPrice);
            map.put("mileagePrice", mileagePrice); // 行驶里程费用
            map.put("travelTimePrice", travelTimePrice); // 服务时间费用
            map.put("mileage", mileage); // 行驶里程 公里
            map.put("travelTime", travelTime); // 执行时间 分钟
            map.put("pay_detail", payDetail); // 支付详情
        } else {
            map.put("success", false);
            map.put("message", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 预算代驾订单价格(根据距离和时间).
     */
    public Map<String, Object> getDaijiaNewPrice(String address, Long passengerId, String acKey, Integer time,
                                                 Double mileage, Double startLat, Double startLng) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/getNewPrice.json?time={time}&mileage={mileage}"));
        Map<String, String> kv = new HashMap<String, String>();
        if (time != null && mileage != null) {
            kv.put("time", String.valueOf(time));
            kv.put("mileage", String.valueOf(mileage));
        } else {
            kv.put("time", String.valueOf(0));
            kv.put("mileage", String.valueOf(0.0));
        }
        if (passengerId != null && passengerId != 0) {
            kv.put("passengerId", String.valueOf(passengerId));
            builder.append("&passengerId={passengerId}");
        }
        if (StringUtils.isNotBlank(acKey)) {
            kv.put("ack", acKey);
            builder.append("&ack={ack}");
        }
        if (startLat != null) {
            kv.put("startLat", String.valueOf(startLat));
            builder.append("&startLat={startLat}");
        }
        if (startLng != null) {
            kv.put("startLng", String.valueOf(startLng));
            builder.append("&startLng={startLng}");
        }
        String result = restTemplate.getForObject(builder.toString(), String.class, kv);

        JSONObject jsonObject = JSON.parseObject(result);

        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("success", true);
            try {
                Double money = jsonObject.getDouble("money");
                map.put("money", money);
            } catch (Exception exx) {
                map.put("money", 0);
            }
            try {
                Double mileagePrice = jsonObject.getDouble("mileagePrice");
                map.put("mileagePrice", mileagePrice); // 行驶里程费用
            } catch (Exception exx) {
                map.put("mileagePrice", 0); // 行驶里程费用
            }
            try {
                Double travelTimePrice = jsonObject.getDouble("travelTimePrice");
                map.put("travelTimePrice", travelTimePrice); // 服务时间费用
            } catch (Exception exx) {
                map.put("travelTimePrice", 0); // 服务时间费用
            }
            Double startPrice = jsonObject.getDouble("startPrice");
            map.put("startPrice", startPrice);
            String payDetail = jsonObject.getString("pay_detail");
            map.put("pay_detail", payDetail); // 支付详情
            map.put("mileage", mileage); // 行驶里程 公里
            map.put("travelTime", time); // 执行时间 分钟
        } else {
            map.put("success", false);
            map.put("message", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 查询单个代驾订单.
     */
    public Map<String, Object> findOne(String address, Long orderId) throws ParseException {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/findOne.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);

        JSONObject jsonObject = JSON.parseObject(result);

        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("msg", "请求成功");
            JSONObject jo = jsonObject.getJSONObject("data");
            Map<String, Object> orderMap = new HashMap<String, Object>();
            orderMap.put("id", jo.getLong("id"));
            orderMap.put("passengerId", jo.getLong("clientId"));
            orderMap.put("companyId", jo.getLong("companyId"));
            orderMap.put("orderNo", jo.getString("orderNo"));
            orderMap.put("passengerName", jo.getString("clientName"));
            orderMap.put("passengerPhone", jo.getString("clientPhone"));
            orderMap.put("userPhone", jo.getString("userPhone"));
            orderMap.put("startAddress", jo.getString("fromPlace"));
            orderMap.put("startLat", jo.getDouble("clientLatitude"));
            orderMap.put("startLng", jo.getDouble("clientLongitude"));
            orderMap.put("endAddress", jo.getString("toPlace"));
            orderMap.put("endLat", jo.getDouble("toPlaceLatitude"));
            orderMap.put("endLng", jo.getDouble("toPlaceLongitude"));
            orderMap.put("status", jo.getInteger("status"));
            String serverTime = jo.getString("serverTime");
            Date date = DateUtils.parseDate(serverTime, "yyyy-MM-dd HH:mm");
            orderMap.put("serverTime", date.getTime());
            orderMap.put("review", jo.getBoolean("review"));
            orderMap.put("treatment", jo.getBoolean("treatment"));
            orderMap.put("budgetPay", jo.getDouble("budgetPay"));
            try {
                orderMap.put("employId", jo.getLong("driverId"));
            } catch (Exception ex) {
                orderMap.put("employId", null);
            }
            try {
                orderMap.put("employName", jo.getString("driverName"));
            } catch (Exception ex) {
                orderMap.put("employName", "");
            }
            try {
                orderMap.put("employNo", jo.getString("driverUserName"));
            } catch (Exception ex) {
                orderMap.put("employNo", "");
            }
            try {
                orderMap.put("employPhone", jo.getString("driverPhone"));
            } catch (Exception ex) {
                orderMap.put("employPhone", "");
            }
            try {
                orderMap.put("employPhoto", jo.getString("driverPhoto"));
            } catch (Exception ex) {
                orderMap.put("employPhoto", "");
            }
            try {
                orderMap.put("employScore", jo.getDouble("driverScore"));
            } catch (Exception ex) {
                orderMap.put("employScore", 5);
            }
            try {
                orderMap.put("orderScore", jo.getDouble("orderScore"));
            } catch (Exception ex) {
                orderMap.put("orderScore", 0);
            }
            try {
                orderMap.put("orderContent", jo.getString("orderContent"));
            } catch (Exception ex) {
                orderMap.put("orderContent", "");
            }
            map.put("data", orderMap);
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 查询代驾订单.
     */
    public Map<String, Object> findOrders(String address, Long passengerId, Integer page, Integer rows)
            throws ParseException {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(
                buildApi(address, "api/daijia/findOrders.json?passengerId={passengerId}&page={page}&rows={rows}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, passengerId, page, rows);

        JSONObject jsonObject = JSON.parseObject(result);

        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("msg", "请求成功");
            JSONObject json = jsonObject.getJSONObject("data");
            Long total = json.getLong("total");

            Map<String, Object> data = new HashMap<String, Object>();

            List<Map<String, Object>> orderList = new ArrayList<Map<String, Object>>();
            JSONArray jsonArray = json.getJSONArray("orderList");

            for (int i = 0; i < jsonArray.size(); i++) {
                Map<String, Object> orderMap = new HashMap<String, Object>();
                JSONObject jo = jsonArray.getJSONObject(i);
                orderMap.put("id", jo.getLong("id"));
                orderMap.put("companyId", jo.getLong("companyId"));
                orderMap.put("companyName", jo.getString("companyName"));
                orderMap.put("orderNo", jo.getString("orderNo"));
                orderMap.put("passengerPhone", jo.getString("passengerPhone"));
                orderMap.put("userPhone", jo.getString("userPhone"));
                orderMap.put("startAddress", jo.getString("startAddress"));
                orderMap.put("startAddressDetail", jo.getString("startAddressDetail"));
                orderMap.put("startLat", jo.getDouble("startLat"));
                orderMap.put("startLng", jo.getDouble("startLng"));
                orderMap.put("endAddress", jo.getString("endAddress"));
                orderMap.put("endAddressDetail", jo.getString("endAddressDetail"));
                orderMap.put("endLat", jo.getDouble("endLat"));
                orderMap.put("endLng", jo.getDouble("endLng"));
                orderMap.put("status", jo.getInteger("status"));
                orderMap.put("serverTime", jo.getLong("serverTime"));
                orderMap.put("review", jo.getBoolean("review"));
                orderMap.put("treatment", jo.getBoolean("treatment"));
                orderMap.put("budgetPay", jo.getDouble("budgetPay"));
                orderMap.put("startPrice", jo.getDouble("startPrice"));
                orderMap.put("mileagePrice", jo.getDouble("mileagePrice"));
                orderMap.put("waitedPrice", jo.getDouble("waitedPrice"));
                orderMap.put("travelPrice", jo.getDouble("travelPrice"));
                try {
                    orderMap.put("createdTime", jo.getLong("createdTime"));
                } catch (Exception ex) {
                    orderMap.put("createdTime", null);
                }
                try {
                    orderMap.put("arriveTime", jo.getLong("arriveTime"));
                } catch (Exception ex) {
                    orderMap.put("arriveTime", null);
                }
                try {
                    orderMap.put("startdriveTime", jo.getLong("startdriveTime"));
                } catch (Exception ex) {
                    orderMap.put("startdriveTime", null);
                }
                try {
                    orderMap.put("mileage", jo.getDouble("mileage"));
                } catch (Exception ex) {
                    orderMap.put("mileage", 0);
                }
                try {
                    orderMap.put("runTime", jo.getInteger("runTime"));
                } catch (Exception ex) {
                    orderMap.put("runTime", 0);
                }
                try {
                    orderMap.put("realPay", jo.getDouble("realPay"));
                } catch (Exception ex) {
                    orderMap.put("realPay", 0);
                }
                try {
                    orderMap.put("employId", jo.getLong("employId"));
                } catch (Exception ex) {
                    orderMap.put("employId", null);
                }
                try {
                    orderMap.put("employName", jo.getString("employName"));
                } catch (Exception ex) {
                    orderMap.put("employName", "");
                }
                try {
                    orderMap.put("employPhone", jo.getString("employPhone"));
                } catch (Exception ex) {
                    orderMap.put("employPhone", "");
                }
                try {
                    orderMap.put("employNo", jo.getString("employNo"));
                } catch (Exception ex) {
                    orderMap.put("employNo", "");
                }
                try {
                    orderMap.put("employPhoto", jo.getString("employPhoto"));
                } catch (Exception ex) {
                    orderMap.put("employPhoto", "");
                }
                try {
                    orderMap.put("employScore", jo.getDouble("employScore"));
                } catch (Exception ex) {
                    orderMap.put("employScore", 5);
                }
                try {
                    orderMap.put("employCompanyId", jo.getLong("employCompanyId"));
                } catch (Exception ex) {
                    orderMap.put("employCompanyId", null);
                }
                try {
                    orderMap.put("orderScore", jo.getDouble("orderScore"));
                } catch (Exception ex) {
                    orderMap.put("orderScore", 0);
                }
                try {
                    orderMap.put("orderContent", jo.getString("orderContent"));
                } catch (Exception ex) {
                    orderMap.put("orderContent", "");
                }
                orderList.add(orderMap);
            }
            data.put("total", total);
            data.put("rows", orderList);
            map.put("data", data);
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 查询服务人员.
     */
    public Map<String, Object> queryDriver(String address, Long driverId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/queryDriver.json?driverId={driverId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, driverId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Long employId = jsonObject.getLong("employId");
            String employName = jsonObject.getString("employName");
            String employAccount = jsonObject.getString("employAccount");
            String employPhone = jsonObject.getString("employPhone");
            String employPhoto = jsonObject.getString("employPhoto");
            Long companyId = jsonObject.getLong("companyId");
            String companyName = jsonObject.getString("companyName");
            String message = jsonObject.getString("message");
            Double employScore = jsonObject.getDouble("employScore");
            Integer status = jsonObject.getInteger("status");
            map.put("employId", employId);
            map.put("employName", employName);
            map.put("employNo", employAccount);
            map.put("employPhone", employPhone);
            map.put("employPhoto", employPhoto);
            map.put("employCompanyId", companyId);
            map.put("employCompanyName", companyName);
            map.put("employScore", employScore);
            map.put("status", status);
            map.put("message", message);
            map.put("success", true);
        } else {
            map.put("success", false);
            map.put("message", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 获取优惠券.
     */
    public Map<String, Object> getCoupons(String address, Long passengerId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/listValidCouponsByPassenger.json?passengerId={passengerId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, passengerId);
        JSONObject jsonObject = JSON.parseObject(result);

        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
            JSONArray jsonArray = jsonObject.getJSONArray("coupons");
            for (int i = 0; i < jsonArray.size(); i++) {
                Map<String, Object> orderMap = new HashMap<String, Object>();
                JSONObject jo = jsonArray.getJSONObject(i);
                orderMap.put("couponId", jo.getLong("couponId"));
                orderMap.put("startTime", jo.getLong("startTime"));
                orderMap.put("endTime", jo.getLong("endTime"));
                orderMap.put("couponCode", jo.getString("couponCode"));
                orderMap.put("couponTitle", jo.getString("couponTitle"));
                orderMap.put("couponMoney", jo.getDouble("couponMoney"));
                data.add(orderMap);
            }
            map.put("data", data);
            map.put("code", 0);
            map.put("msg", "获取优惠券成功");
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 获取微信,支付宝信息是否配置好.
     */
    public Map<String, Object> queryPaySetting(String address) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/system/queryPaySetting.json"));
        String result = restTemplate.getForObject(builder.toString(), String.class);
        JSONObject jsonObject = JSON.parseObject(result);

        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Boolean weixinPay = jsonObject.getBoolean("weixinPay");
            Boolean aliPay = jsonObject.getBoolean("aliPay");
            map.put("weixinPay", weixinPay);
            map.put("aliPay", aliPay);
            try {
                Boolean unionPay = jsonObject.getBoolean("unionPay");
                map.put("unionPay", unionPay);
            } catch (Exception e) {
                map.put("unionPay", false);
            }
            try {
                Boolean bestPay = jsonObject.getBoolean("bestPay");
                map.put("bestPay", bestPay);
            } catch (Exception e) {
                map.put("bestPay", false);
            }
        } else {
            map.put("weixinPay", false);
            map.put("aliPay", false);
            map.put("unionPay", false);
            map.put("bestPay", false);
        }
        return map;
    }

    /**
     * 催促专车订单进度.
     */
    public String hastenZhuanOrder(String server, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/zhuanche/hurryOrder"));
        builder.append("?orderId={orderId}");
        String response = restTemplate.getForObject(builder.toString(), String.class, orderId);
        return response;
    }

    /**
     * 查询用户所在地的专车车辆类型.
     */
    public JSONArray getCarTypes(String server, String ack, Long passengerId, double longitude, double latitude) {
        String response = restTemplate.getForObject(buildApi(server, GET_CARTYPE), String.class, ack, passengerId,
                longitude, latitude);

        JSONArray jsonArray = JSON.parseArray(response);

        return jsonArray;
    }

    /**
     * 查询收费标准.
     */
    public JSONObject findCarType(String server, String ack, Long passengerId, Long carTypeId, double longitude,
                                  double latitude) {
        String response = restTemplate.getForObject(buildApi(server, FIND_CARTYPE), String.class, ack, passengerId,
                carTypeId, longitude, latitude);
        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 获取专车微信预支付.
     */
    public JSONObject getZcWxPrepayId(String server, Long orderId, String openid) {

        String response = restTemplate.getForObject(buildApi(server, GET_ZC_WX_PREPAYID), String.class, orderId,
                openid);

        return JSON.parseObject(response);
    }

    /**
     * 获取跑腿微信预支付.
     */
    public JSONObject getPtWxPrepayId(String server, Long orderId, String openid) {

        String response = restTemplate.getForObject(buildApi(server, GET_PT_WX_PREPAYID), String.class, orderId,
                openid);

        return JSON.parseObject(response);
    }

    /**
     * 查询附近的专车司机.
     */

    public JSONObject countZhuancheNearDriver(String address, Double lng, Double lat, long carTypeId) {
        String response = restTemplate.getForObject(buildApi(address, QUERY_ZC_NEAR_DRIVER), String.class, lng, lat,
                carTypeId);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 预算专车价格.
     */
    public JSONObject calculationZhuanchePrice(String server, Long carTypeId, double startLat, double startLng,
                                               double endLat, double endLng) {

        String response = restTemplate.getForObject(buildApi(server, GET_PRICE_BY_CARTYPE), String.class, carTypeId,
                startLat, startLng, endLat, endLng);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 专车预算费用V4.
     */

    public JSONObject calculationZhuanchePriceV4(String server, Long areaId, Double startLat, Double startLng,
                                                 Double endLat, Double endLng) {

        String response = restTemplate.getForObject(buildApi(server, GET_PRICEV4), String.class, areaId, startLat,
                startLng, endLat, endLng);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 专车下单.
     */

    public String makeAnZhuancheAppointment(String server, String ack, String beginAddress, String beginAddressDetail,
                                            Double beginLat, Double beginLng, String endAddress, String endAddressDetail, Double endLat, Double endLng,
                                            String phone, String openId, Long carTypeId) {
        Map<String, Object> params = new HashMap<>();
        params.put("ack", ack);
        params.put("beginAddress", beginAddress);
        params.put("beginAddressDetail", beginAddressDetail);
        params.put("beginLat", beginLat);
        params.put("beginLng", beginLng);
        params.put("endAddress", endAddress);
        params.put("endAddressDetail", endAddressDetail);
        params.put("endLat", endLat);
        params.put("endLng", endLng);
        params.put("phone", phone);
        params.put("openId", openId);
        params.put("carTypeId", carTypeId);

        String response = restTemplate.postForObject(buildApi(server, CREATE_ZC_FROM_WEIXIN), null, String.class,
                params);

        return response;
    }

    /**
     * 查询专车订单.
     */
    public JSONObject findZhuancheOrder(String server, long orderId) {
        String response = restTemplate.getForObject(buildApi(server, QUERY_ONE_ZHUANCHE_ORDER), String.class, orderId);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 专车销单,并且退款.
     */
    public JSONObject cancelZhuancheOrder(String server, long orderId, String reson) {

        String response = restTemplate.postForObject(buildApi(server, CANCEL_ZHUANCHE_ORDER), null, String.class,
                orderId, reson);
        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 专车销单v4.
     */

    public ResultTransport cancelZhuancheOrderV4(String server, long orderId, String cause) {
        String result = restTemplate.postForObject(buildApi(server, CANCEL_ZHUANCHE_ORDER_V4), null, String.class,
                orderId, cause);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 专车客户销单.
     */

    public ResultTransport cancelZhuancheOrderCustomer(String server, Long orderId, String cause) {

        String result = restTemplate.postForObject(buildApi(server, CANCEL_ZHUANCHE_ORDER), null, String.class, orderId,
                cause);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 查询专车司机位置信息.
     */
    public Map<String, Object> getDriverPlace(String address, Long driverId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/zhuanche/getDriverPlace.json?driverId={driverId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, driverId);
        JSONObject jsonObject = JSON.parseObject(result);

        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Double longitude = jsonObject.getDouble("longitude");
            Double latitude = jsonObject.getDouble("latitude");
            String phone = jsonObject.getString("phone");
            Map<String, Object> map2 = new HashMap<String, Object>();
            map2.put("lng", longitude);
            map2.put("lat", latitude);
            map2.put("phone", phone);
            try {
                map2.put("place", jsonObject.getString("place"));
            } catch (Exception ex) {
                map2.put("place", "位置不详细");
            }
            map.put("code", 0);
            map.put("msg", "成功");
            map.put("data", map2);
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 查询附近专车司机.
     */

    public Map<String, Object> queryNearDriver(String address, Double longitude, Double latitude, Long carTypeId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/zhuanche/queryNearDriver.json?longitude={longitude}"
                + "&latitude={latitude}&carTypeId={carTypeId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, longitude, latitude, carTypeId);
        JSONObject jsonObject = JSON.parseObject(result);

        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            for (int i = 0; i < jsonArray.size(); i++) {
                Map<String, Object> orderMap = new HashMap<String, Object>();
                JSONObject jo = jsonArray.getJSONObject(i);
                orderMap.put("driverId", jo.getLong("driverId"));
                orderMap.put("driverName", jo.getString("driverName"));
                orderMap.put("driverUserName", jo.getString("driverUserName"));
                orderMap.put("driverHead", jo.getString("driverHead"));
                orderMap.put("driverStar", jo.getDouble("driverStar"));
                orderMap.put("driverTimes", jo.getInteger("driverTimes"));
                orderMap.put("driverJialing", jo.getIntValue("driverJialing"));
                orderMap.put("driverDistance", jo.getString("driverDistance"));
                orderMap.put("driverMeter", jo.getDouble("driverMeter"));
                orderMap.put("driverStatus", jo.getIntValue("driverStatus"));
                orderMap.put("driverLng", jo.getDouble("driverLng"));
                orderMap.put("driverLat", jo.getDouble("driverLat"));
                orderMap.put("carPhoto", jo.getString("carPhoto"));
                orderMap.put("carName", jo.getString("carName"));
                data.add(orderMap);
            }
            map.put("data", data);
            map.put("code", 0);
            map.put("msg", "查询司机成功");
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            map.put("data", null);
        }
        return map;
    }

    /**
     * 专车预算价格.
     */
    public Map<String, Object> getZhuanchePrice(String address, Long areaId, Double startLat, Double startLng,
                                                Double endLat, Double endLng) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/zhuanche/getPrice.json?areaId={areaId}"
                + "&startLat={startLat}&startLng={startLng}&endLat={endLat}&endLng={endLng}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, areaId, startLat, startLng, endLat,
                endLng);

        JSONObject jsonObject = JSON.parseObject(result);

        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Double money = jsonObject.getDouble("money");
            Double mileage = jsonObject.getDouble("mileage");
            Double startPrice = jsonObject.getDouble("startPrice");
            Double mileagePrice = jsonObject.getDouble("mileagePrice");
            Double travelTimePrice = jsonObject.getDouble("travelTimePrice");
            Long travelTime = jsonObject.getLong("travelTime");
            String payDetail = jsonObject.getString("pay_detail");
            map.put("success", true);
            map.put("money", money);
            map.put("startPrice", startPrice);
            map.put("mileagePrice", mileagePrice); // 行驶里程费用
            map.put("travelTimePrice", travelTimePrice); // 服务时间费用
            map.put("mileage", mileage); // 行驶里程 公里
            map.put("travelTime", travelTime); // 执行时间 分钟
            map.put("pay_detail", payDetail); // 支付详情
        } else {
            map.put("success", false);
            map.put("message", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 专车预算价格(根据距离和时间).
     */
    public Map<String, Object> getZhuancheNewPrice(String address, Long areaId, Integer time, Double mileage) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(
                buildApi(address, "api/zhuanche/getNewPrice.json?areaId={areaId}&time={time}&mileage={mileage}"));
        String result = "";
        if (null != time && null != mileage) {
            result = restTemplate.getForObject(builder.toString(), String.class, areaId, time, mileage);
        } else {
            result = restTemplate.getForObject(builder.toString(), String.class, areaId, 0, 0.0);
        }

        JSONObject jsonObject = JSON.parseObject(result);

        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("success", true);
            Double money = jsonObject.getDouble("money");
            map.put("money", money);
            Double mileagePrice = jsonObject.getDouble("mileagePrice");
            map.put("mileagePrice", mileagePrice); // 行驶里程费用
            Double travelTimePrice = jsonObject.getDouble("travelTimePrice");
            map.put("travelTimePrice", travelTimePrice); // 服务时间费用
            Double startPrice = jsonObject.getDouble("startPrice");
            map.put("startPrice", startPrice);
            String payDetail = jsonObject.getString("pay_detail");
            map.put("pay_detail", payDetail); // 支付详情
            map.put("mileage", mileage); // 行驶里程 公里
            map.put("travelTime", time); // 执行时间 分钟
        } else {
            map.put("success", false);
            map.put("message", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 催促货运订单进度.
     */
    public String hastenFreightOrder(String server, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/freight/hurryOrder"));
        builder.append("?orderId={orderId}");
        String response = restTemplate.getForObject(builder.toString(), String.class, orderId);
        return response;
    }

    /**
     * 货运预算价格(根据距离和时间).
     */
    public Map<String, Object> getFreightPrice(String address, Long areaId, Long time, Double mileage) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/freight/getPrice.json?areaId={areaId}&time={time}&mileage={mileage}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, areaId, time, mileage);

        JSONObject jsonObject = JSON.parseObject(result);

        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Double money = jsonObject.getDouble("money");
            Double startPrice = jsonObject.getDouble("startPrice");
            Double mileagePrice = jsonObject.getDouble("mileagePrice");
            Double travelTimePrice = jsonObject.getDouble("travelTimePrice");
            String payDetail = jsonObject.getString("pay_detail");
            map.put("success", true);
            map.put("money", money);
            map.put("startPrice", startPrice);
            map.put("mileagePrice", mileagePrice); // 行驶里程费用
            map.put("travelTimePrice", travelTimePrice); // 服务时间费用
            map.put("mileage", mileage); // 行驶里程 公里
            map.put("travelTime", time); // 执行时间 分钟
            map.put("pay_detail", payDetail); // 支付详情
        } else {
            map.put("success", false);
            map.put("message", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 请求代驾支付宝支付接口.
     */
    public Map<String, Object> daijiaaliPrepay(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/alipay/prepay.json?orderId={orderId}&orderType={orderType}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId, "daijia");
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            String url = jsonObject.getString("url");
            map.put("code", 0);
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("url", url);

            map.put("data", data);
            map.put("msg", "请求成功");
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 请求代驾微信支付接口.
     */
    public Map<String, Object> daijiawxPrepay(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/wx/prepay.json?orderId={orderId}&orderType={orderType}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId, "daijia");
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("appid", jsonObject.getString("appid"));
            data.put("noncestr", jsonObject.getString("noncestr"));
            data.put("package", jsonObject.getString("package"));
            data.put("partnerid", jsonObject.getString("partnerid"));
            data.put("prepayid", jsonObject.getString("prepayid"));
            data.put("timestamp", jsonObject.getString("timestamp"));
            data.put("sign", jsonObject.getString("sign"));
            map.put("data", data);
            map.put("msg", "请求成功");
        } else {
            map.put("code", -1);
            System.err.println(jsonObject.getString("message"));
            map.put("msg", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 请求代驾的余额,签单预支付接口.
     */
    public Map<String, Object> balanceSignPayDaijia(String address, Long orderId, Long passengerId, String payType) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address,
                "api/daijia/balancesignPay.json?orderId={orderId}" + "&passengerId={passengerId}&payType={payType}"));
        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.put("orderId", orderId);
        map2.put("passengerId", passengerId);
        map2.put("payType", payType);
        String result = restTemplate.postForObject(builder.toString(), null, String.class, map2);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("data", null);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 请求专车的余额,签单预支付接口.
     */
    public Map<String, Object> balanceSignPayZhuan(String address, Long orderId, Long passengerId, String payType) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address,
                "api/zhuanche/balancesignPay.json?orderId={orderId}" + "&passengerId={passengerId}&payType={payType}"));
        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.put("orderId", orderId);
        map2.put("passengerId", passengerId);
        map2.put("payType", payType);
        String result = restTemplate.postForObject(builder.toString(), null, String.class, map2);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("data", null);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 实时获取代驾订单是否被结算.
     */
    public Map<String, Object> checkTaskDaijia(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/checkTask.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("data", jsonObject.getBoolean("finished"));
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 实时检测代驾订单是否被结算.
     */

    public ResultTransport checkTaskDaijiaV4(String address, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/v4/checkTask.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 实时获取专车订单是否被结算.
     */
    public Map<String, Object> checkTaskZhuan(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/zhuanche/checkTask.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("data", jsonObject.getBoolean("finished"));
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 实时检测专车订单是否被结算.
     */

    public ResultTransport checkTaskZhuanV4(String address, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/zhuanche/v4/checkTask.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 专车订单结算页面的数据.
     */
    public Map<String, Object> completeTaskZhuan(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/zhuanche/completeTaskData.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("id", jsonObject.getLong("orderId"));
            data.put("orderNumber", jsonObject.getString("orderNumber"));
            data.put("orderType", jsonObject.getString("orderType"));
            data.put("passengerPhone", jsonObject.getString("passengerPhone"));
            data.put("passengerName", jsonObject.getString("passengerName"));
            data.put("passengerType", jsonObject.getString("passengerType"));
            data.put("orderCompanyName", jsonObject.getString("orderCompanyName"));
            data.put("passengerCompanyName", jsonObject.getString("passengerCompanyName"));
            data.put("overdraw", jsonObject.getBoolean("overdraw"));
            data.put("virtual", jsonObject.getString("virtual"));
            try {
                data.put("couponMoney", jsonObject.getDouble("couponMoney"));
            } catch (Exception ex) {
                data.put("couponMoney", null);
            }
            try {
                data.put("discount", jsonObject.getDouble("discount"));
            } catch (Exception ex) {
                data.put("discount", null);
            }
            data.put("preyMoney", jsonObject.getDouble("preyMoney"));
            data.put("employId", jsonObject.getLong("employId"));
            data.put("employName", jsonObject.getString("employName"));
            data.put("employPhone", jsonObject.getString("employPhone"));
            map.put("data", data);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 确认费用V4.
     */

    public ResultTransport completeTaskZhuanV4(String address, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/zhuanche/v4/completeTaskData.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 代驾获取结算界面数据.
     */
    public Map<String, Object> completeTaskDaijia(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/completeTaskData.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("id", jsonObject.getLong("orderId"));
            data.put("orderNumber", jsonObject.getString("orderNumber"));
            data.put("orderType", jsonObject.getString("orderType"));
            data.put("passengerPhone", jsonObject.getString("passengerPhone"));
            data.put("passengerName", jsonObject.getString("passengerName"));
            data.put("passengerType", jsonObject.getString("passengerType"));
            data.put("orderCompanyName", jsonObject.getString("orderCompanyName"));
            data.put("passengerCompanyName", jsonObject.getString("passengerCompanyName"));
            data.put("overdraw", jsonObject.getString("overdraw"));
            data.put("virtual", jsonObject.getString("virtual"));
            try {
                data.put("couponMoney", jsonObject.getDouble("couponMoney"));
            } catch (Exception ex) {
                data.put("couponMoney", null);
            }
            data.put("preyMoney", jsonObject.getDouble("preyMoney"));
            data.put("employId", jsonObject.getLong("employId"));
            data.put("employName", jsonObject.getString("employName"));
            data.put("employPhone", jsonObject.getString("employPhone"));
            try {
                data.put("discount", jsonObject.getDouble("discount"));
            } catch (Exception ex) {
                data.put("discount", null);
            }
            map.put("data", data);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 确认代驾订单费用V4.
     */

    public ResultTransport completeTaskDaijiaV4(String address, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/v4/completeTaskData.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 代驾订单客户端支付所需数据.
     */
    public Map<String, Object> clientPayDataDaijia(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/clientPayData.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("id", orderId);
            data.put("realCash", jsonObject.getDouble("realCash"));
            data.put("guoluMoney", jsonObject.getDouble("guoluMoney"));
            data.put("yuanchengMoney", jsonObject.getDouble("yuanchengMoney"));
            data.put("otherMoney", jsonObject.getDouble("otherMoney"));
            data.put("preyMoney", jsonObject.getDouble("preyMoney"));
            data.put("couponMoney", jsonObject.getDouble("couponMoney"));
            data.put("payMoney", jsonObject.getDouble("payMoney"));
            data.put("weixinPay", jsonObject.getBoolean("weixinPay"));
            try {
                data.put("unionPay", jsonObject.getBoolean("unionPay"));
            } catch (Exception e) {
                data.put("unionPay", Boolean.FALSE);
            }
            data.put("aliPay", jsonObject.getBoolean("aliPay"));
            data.put("overdraw", jsonObject.getBoolean("overdraw"));
            map.put("data", data);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 专车订单客户端支付所需数据.
     */
    public Map<String, Object> clientPayDataZhuan(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/zhuanche/clientPayData.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("id", orderId);
            data.put("realCash", jsonObject.getDouble("realCash"));
            data.put("guoluMoney", jsonObject.getDouble("guoluMoney"));
            data.put("yuanchengMoney", jsonObject.getDouble("yuanchengMoney"));
            data.put("otherMoney", jsonObject.getDouble("otherMoney"));
            data.put("preyMoney", jsonObject.getDouble("preyMoney"));
            data.put("couponMoney", jsonObject.getDouble("couponMoney"));
            data.put("payMoney", jsonObject.getDouble("payMoney"));
            data.put("weixinPay", jsonObject.getBoolean("weixinPay"));
            data.put("aliPay", jsonObject.getBoolean("aliPay"));
            data.put("mileage", jsonObject.getDouble("mileage"));
            data.put("runTime", jsonObject.getInteger("runTime"));
            data.put("mileagePrice", jsonObject.getDouble("mileagePrice"));
            data.put("runTimePrice", jsonObject.getDouble("runTimePrice"));
            data.put("midwayWait", jsonObject.getInteger("midwayWait"));
            data.put("waitPrice", jsonObject.getDouble("waitPrice"));
            try {
                data.put("unionPay", jsonObject.getBoolean("unionPay"));
            } catch (Exception e) {
                data.put("unionPay", Boolean.FALSE);
            }
            data.put("overdraw", jsonObject.getBoolean("overdraw"));
            map.put("data", data);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 客户端支付宝结算代驾订单.
     */
    public Map<String, Object> aliAfterpayDaijia(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/alipay/afterpay.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Map<String, Object> data = new HashMap<String, Object>();
            String url = jsonObject.getString("url");
            data.put("url", url);
            map.put("data", data);
            map.put("code", 0);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 客户端支付宝结算专车订单.
     */
    public Map<String, Object> aliAfterpayZhuan(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/zhuanche/alipay/afterpay.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Map<String, Object> data = new HashMap<String, Object>();
            String url = jsonObject.getString("url");
            data.put("url", url);
            map.put("data", data);
            map.put("code", 0);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * V2确认跑腿订单费用.
     */
    public Map<String, Object> confirmTaskErrand(String address, Long orderId, Double realCash, Double guoluMoney,
                                                 Double yuanchengMoney, Double otherMoney, Double mileage, Integer waitedTime, Integer travelTime,
                                                 Double startPrice, Double mileagePrice, Double runTimePrice, Double waitPrice, String memo, String xml) {
        Map<String, Object> map = new HashMap<String, Object>();

        MultiValueMap<String, String> map2 = new LinkedMultiValueMap<String, String>();

        map2.add("orderId", String.valueOf(orderId));
        map2.add("realCash", String.valueOf(realCash));
        if (StringUtils.isNotBlank(memo)) {
            map2.add("memo", memo);
        }
        map2.add("guoluMoney", String.valueOf(guoluMoney));
        map2.add("yuanchengMoney", String.valueOf(yuanchengMoney));
        map2.add("otherMoney", String.valueOf(otherMoney));
        map2.add("mileage", String.valueOf(mileage));
        map2.add("waitedTime", String.valueOf(waitedTime));
        map2.add("travelTime", String.valueOf(travelTime));
        map2.add("startPrice", String.valueOf(startPrice));
        map2.add("mileagePrice", String.valueOf(mileagePrice));
        map2.add("runTimePrice", String.valueOf(runTimePrice));
        map2.add("waitPrice", String.valueOf(waitPrice));
        map2.add("xml", xml);
        try {

            RestTemplate rest = new RestTemplate();

            String result = rest.postForObject(buildApi(address, "api/errand/confirmTask.json"), map2, String.class);

            JSONObject jsonObject = JSON.parseObject(result);
            Boolean success = jsonObject.getBoolean("success");
            if (success) {
                Map<String, Object> data = new HashMap<String, Object>();
                data.put("type", jsonObject.getString("type"));
                map.put("data", data);
                map.put("code", 0);
                map.put("msg", jsonObject.getString("message"));
            } else {
                map.put("code", -1);
                map.put("msg", jsonObject.getString("message"));
            }

        } catch (HttpClientErrorException ex) {
            map.put("code", -1);
            map.put("msg", ex.getResponseBodyAsString());
        } catch (HttpServerErrorException ex) {
            map.put("code", -1);
            map.put("msg", ex.getResponseBodyAsString());
        }

        return map;
    }

    /**
     * 确认跑腿订单费用V4.
     */

    public ResultTransport confirmTaskErrandV4(String address, Long orderId, Double realCash, Double goodsCash,
                                               Double thanksCash, Double guoluMoney, Double yuanchengMoney, Double otherMoney, Double mileage,
                                               Integer waitedTime, Integer travelTime, Double startPrice, Double mileagePrice, Double runTimePrice,
                                               Double waitPrice, String memo, String jsonLocs) {
        MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();

        map.add("orderId", String.valueOf(orderId));
        map.add("realCash", String.valueOf(realCash));
        map.add("goodsCash", String.valueOf(goodsCash != null ? goodsCash : 0));
        map.add("thanksCash", String.valueOf(thanksCash != null ? thanksCash : 0));
        if (StringUtils.isNotBlank(memo)) {
            map.add("memo", memo);
        }
        if (StringUtils.isNotBlank(jsonLocs)) {
            map.add("jsonLocs", jsonLocs);
        }
        map.add("guoluMoney", String.valueOf(guoluMoney));
        map.add("yuanchengMoney", String.valueOf(yuanchengMoney));
        map.add("otherMoney", String.valueOf(otherMoney));
        map.add("mileage", String.valueOf(mileage));
        map.add("waitedTime", String.valueOf(waitedTime));
        map.add("travelTime", String.valueOf(travelTime));
        map.add("startPrice", String.valueOf(startPrice));
        map.add("mileagePrice", String.valueOf(mileagePrice));
        map.add("runTimePrice", String.valueOf(runTimePrice));
        map.add("waitPrice", String.valueOf(waitPrice));

        RestTemplate rest = new RestTemplate();

        String result = rest.postForObject(buildApi(address, "api/errand/v4/confirmTask.json"), map, String.class);

        ResultTransport parseObject = JSON.parseObject(result, ResultTransport.class);

        return parseObject;
    }

    /**
     * 根据经纬度,ackey,客户所在公司Id筛选公司id和公司名称.
     */

    public JSONObject getCompanyIdAndName(String server, String acKey, Long companyId, Double longitude,
                                          Double latitude) {
        Map<String, String> kv = new HashMap<String, String>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, GET_COMPANYIDANDNAME));
        if (StringUtils.isNotBlank(acKey)) {
            kv.put("acKey", acKey);
            builder.append("&acKey={acKey}");
        }
        if (companyId != null) {
            kv.put("companyId", String.valueOf(companyId));
            builder.append("&companyId={companyId}");
        }
        if (longitude != null && latitude != null) {
            kv.put("longitude", String.valueOf(longitude));
            kv.put("latitude", String.valueOf(latitude));
            builder.append("&longitude={longitude}&latitude={latitude}");
        }
        String url = builder.toString();
        if (!url.contains("?") && url.contains("&")) {
            url = url.replaceFirst("&", "?");
        }
        String response = restTemplate.getForObject(url, String.class, kv);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * V2筛选公司.
     *
     * @param server    系统地址
     * @param acKey     客户端区分公司 (选填)
     * @param companyId 客户所在公司id (选填)
     * @param longitude 客户当前位置经度 (选填)
     * @param latitude  客户当前位置纬度 (选填)
     */
    public JSONObject getCompanyByAppKey(String server, String acKey, Long companyId, Double longitude,
                                         Double latitude) {
        Map<String, String> kv = new HashMap<String, String>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, GET_COMPANYBYAREA));
        if (StringUtils.isNotBlank(acKey)) {
            kv.put("acKey", acKey);
            builder.append("&acKey={acKey}");
        }
        if (companyId != null) {
            kv.put("companyId", String.valueOf(companyId));
            builder.append("&companyId={companyId}");
        }
        if (longitude != null && latitude != null) {
            kv.put("longitude", String.valueOf(longitude));
            kv.put("latitude", String.valueOf(latitude));
            builder.append("&longitude={longitude}&latitude={latitude}");
        }
        String url = builder.toString();
        if (!url.contains("?") && url.contains("&")) {
            url = url.replaceFirst("&", "?");
        }
        String response = restTemplate.getForObject(url, String.class, kv);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 查询单个收费标准.
     */

    public JSONObject findChargeStartTime(String server, Long areaId) {
        String result = restTemplate.getForObject(buildApi(server, QUERY_CHARGESTARTTIMES), String.class, areaId);

        JSONObject jsonObject = JSON.parseObject(result);

        return jsonObject;
    }

    /**
     * 微信后支付代驾订单.
     */

    public Map<String, Object> wxAfterpayDaijia(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/wx/afterpay.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("appid", jsonObject.getString("appid"));
            data.put("noncestr", jsonObject.getString("noncestr"));
            data.put("package", jsonObject.getString("package"));
            data.put("partnerid", jsonObject.getString("partnerid"));
            data.put("prepayid", jsonObject.getString("prepayid"));
            data.put("timestamp", jsonObject.getString("timestamp"));
            data.put("sign", jsonObject.getString("sign"));
            map.put("data", data);
            map.put("code", 0);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 微信后支付代驾订单V4.
     */

    public Map<String, Object> wxAfterpayDaijiaV4(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/v4/wx/afterpay.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("appid", jsonObject.getString("appid"));
            data.put("noncestr", jsonObject.getString("noncestr"));
            data.put("package", jsonObject.getString("package"));
            data.put("partnerid", jsonObject.getString("partnerid"));
            data.put("prepayid", jsonObject.getString("prepayid"));
            data.put("timestamp", jsonObject.getString("timestamp"));
            data.put("sign", jsonObject.getString("sign"));
            map.put("data", data);
            map.put("code", 0);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 代驾完成结算.
     *
     * @param payType 支付类型: helppay(代付) sign(签单) balance(余额)
     */

    public Map<String, Object> finishTaskDaijia(String address, Long orderId, String payType, String who) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/daijia/finishTask.json?orderId={orderId}&payType={payType}"));
        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.put("orderId", orderId);
        map2.put("payType", payType);
        if (StringUtils.isNotBlank(who)) {
            builder.append("&who={who}");
            map2.put("who", who);
        }
        String result = restTemplate.postForObject(builder.toString(), null, String.class, map2);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("msg", jsonObject.getString("message"));
            map.put("data", null);
        } else {
            map.put("msg", jsonObject.getString("message"));// 余额不足
            String message = jsonObject.getString("message");
            if ("余额不足".equals(message)) {
                map.put("code", -3);
            } else if ("订单已结算".equals(message)) {
                map.put("code", -78);
            } else {
                map.put("code", -1);
            }
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 完成代驾订单V4.
     */

    public ResultTransport finishTaskDaijiaV4(String address, Long orderId, String payType, String who) {
        Map<String, Object> map = new HashMap<String, Object>();

        StringBuilder builder = new StringBuilder();

        builder.append(buildApi(address, "api/daijia/v4/finishTask.json?orderId={orderId}&payType={payType}"));
        map.put("orderId", orderId);
        map.put("payType", payType);
        if (StringUtils.isNotBlank(who)) {
            builder.append("&who={who}");
            map.put("who", who);
        }
        String result = restTemplate.postForObject(builder.toString(), null, String.class, map);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 代驾订单结算接口.
     */

    public Map<String, Object> confirmTaskDaijia(String address, Long orderId, Double discount, Double realCash,
                                                 Double guoluMoney, Double yuanchengMoney, Double otherMoney, Double mileage, Integer waitedTime,
                                                 Integer travelTime, Double startPrice, Double mileagePrice, Double runTimePrice, Double waitedPrice,
                                                 String xml, String toPlace, Double toPlaceLng, Double toPlaceLat, String memo) {
        Map<String, Object> map = new HashMap<String, Object>();

        MultiValueMap<String, String> map2 = new LinkedMultiValueMap<String, String>();

        if (discount != null && discount != 0) {
            map2.add("discount", String.valueOf(discount));
        }
        if (StringUtils.isNotBlank(toPlace)) {
            map2.add("toPlace", toPlace);
        }
        if (toPlaceLng != null && toPlaceLng != 0) {
            map2.add("toPlaceLng", String.valueOf(toPlaceLng));
        }
        if (toPlaceLat != null && toPlaceLat != 0) {
            map2.add("toPlaceLat", String.valueOf(toPlaceLat));
        }

        map2.add("orderId", String.valueOf(orderId));
        map2.add("realCash", String.valueOf(realCash));
        map2.add("guoluMoney", String.valueOf(guoluMoney));
        map2.add("yuanchengMoney", String.valueOf(yuanchengMoney));
        map2.add("otherMoney", String.valueOf(otherMoney));
        map2.add("mileage", String.valueOf(mileage));
        map2.add("waitedTime", String.valueOf(waitedTime));
        map2.add("travelTime", String.valueOf(travelTime));
        if (startPrice != null) {
            map2.add("startPrice", String.valueOf(startPrice));
        }
        if (mileagePrice != null) {
            map2.add("mileagePrice", String.valueOf(mileagePrice));
        }
        if (runTimePrice != null) {
            map2.add("runTimePrice", String.valueOf(runTimePrice));
        }
        if (waitedPrice != null) {
            map2.add("waitPrice", String.valueOf(waitedPrice));
        }
        map2.add("xml", xml);
        if (StringUtils.isNotBlank(memo)) {
            map2.add("memo", memo);
        }
        try {
            RestTemplate rest = new RestTemplate();

            String result = rest.postForObject(buildApi(address, "api/daijia/confirmTask.json"), map2, String.class);

            JSONObject jsonObject = JSON.parseObject(result);
            Boolean success = jsonObject.getBoolean("success");
            if (success) {
                Map<String, Object> data = new HashMap<String, Object>();
                data.put("type", jsonObject.getString("type"));
                map.put("data", data);
                map.put("code", 0);
                map.put("msg", jsonObject.getString("message"));
            } else {
                map.put("code", -1);
                map.put("msg", jsonObject.getString("message"));
            }
            return map;

        } catch (HttpClientErrorException ex) {
            map.put("code", -1);
            map.put("msg", ex.getResponseBodyAsString());
        } catch (HttpServerErrorException ex) {
            map.put("code", -1);
            map.put("msg", ex.getResponseBodyAsString());
        }

        return map;
    }

    /**
     * 确认代驾订单费用V4.
     */

    public ResultTransport confirmTaskDaijiaV4(String address, Long orderId, Double realCash, Double guoluMoney,
                                               Double yuanchengMoney, Double otherMoney, Double mileage, Integer waitedTime, Integer travelTime,
                                               Double startPrice, Double mileagePrice, Double runTimePrice, Double waitedPrice, String toPlace,
                                               Double toPlaceLng, Double toPlaceLat, String memo, String jsonLocs) {
        MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();

        if (StringUtils.isNotBlank(toPlace)) {
            map.add("toPlace", toPlace);
        }
        if (toPlaceLng != null && toPlaceLng != 0) {
            map.add("toPlaceLng", String.valueOf(toPlaceLng));
        }
        if (toPlaceLat != null && toPlaceLat != 0) {
            map.add("toPlaceLat", String.valueOf(toPlaceLat));
        }

        map.add("orderId", String.valueOf(orderId));
        map.add("realCash", String.valueOf(realCash));
        map.add("guoluMoney", String.valueOf(guoluMoney));
        map.add("yuanchengMoney", String.valueOf(yuanchengMoney));
        map.add("otherMoney", String.valueOf(otherMoney));
        map.add("mileage", String.valueOf(mileage));
        map.add("waitedTime", String.valueOf(waitedTime));
        map.add("travelTime", String.valueOf(travelTime));
        if (startPrice != null) {
            map.add("startPrice", String.valueOf(startPrice));
        }
        if (mileagePrice != null) {
            map.add("mileagePrice", String.valueOf(mileagePrice));
        }
        if (runTimePrice != null) {
            map.add("runTimePrice", String.valueOf(runTimePrice));
        }
        if (waitedPrice != null) {
            map.add("waitPrice", String.valueOf(waitedPrice));
        }
        if (StringUtils.isNotBlank(memo)) {
            map.add("memo", memo);
        }
        if (StringUtils.isNotBlank(jsonLocs)) {
            map.add("jsonLocs", jsonLocs);
        }
        RestTemplate rest = new RestTemplate();

        String result = rest.postForObject(buildApi(address, "api/daijia/v4/confirmTask.json"), map, String.class);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 客户端微信结算专车订单.
     */

    public Map<String, Object> wxAfterpayZhuan(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/zhuanche/wx/afterpay.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("appid", jsonObject.getString("appid"));
            data.put("noncestr", jsonObject.getString("noncestr"));
            data.put("package", jsonObject.getString("package"));
            data.put("partnerid", jsonObject.getString("partnerid"));
            data.put("prepayid", jsonObject.getString("prepayid"));
            data.put("timestamp", jsonObject.getString("timestamp"));
            data.put("sign", jsonObject.getString("sign"));
            map.put("data", data);
            map.put("code", 0);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 专车完成结算.
     */

    public Map<String, Object> finishTaskZhuan(String address, Long orderId, String payType, String who) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/zhuanche/finishTask.json?orderId={orderId}&payType={payType}"));
        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.put("orderId", orderId);
        map2.put("payType", payType);
        if (StringUtils.isNotBlank(who)) {
            builder.append("&who={who}");
            map2.put("who", who);
        }
        String result = restTemplate.postForObject(builder.toString(), null, String.class, map2);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("msg", jsonObject.getString("message"));
            map.put("data", null);
        } else {
            map.put("msg", jsonObject.getString("message"));// 余额不足
            String message = jsonObject.getString("message");
            if ("余额不足".equals(message)) {
                map.put("code", -3);
            } else if ("订单已结算".equals(message)) {
                map.put("code", -78);
            } else {
                map.put("code", -1);
            }
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 完成专车订单V4.
     */

    public ResultTransport finishTaskZhuanV4(String address, Long orderId, String payType, String who) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/zhuanche/v4/finishTask.json?orderId={orderId}&payType={payType}"));
        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.put("orderId", orderId);
        map2.put("payType", payType);
        if (StringUtils.isNotBlank(who)) {
            builder.append("&who={who}");
            map2.put("who", who);
        }
        String result = restTemplate.postForObject(builder.toString(), null, String.class, map2);
        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 专车订单结算接口.
     */

    public Map<String, Object> confirmTaskZhuan(String address, Long orderId, Double realCash, Double guoluMoney,
                                                Double yuanchengMoney, Double otherMoney, Double mileage, Integer waitedTime, Integer travelTime,
                                                String xml, String toPlace, Double toPlaceLng, Double toPlaceLat, Double startPrice, Double mileagePrice,
                                                Double runTimePrice, Double waitPrice, String memo) {

        Map<String, Object> map = new HashMap<String, Object>();

        MultiValueMap<String, String> map2 = new LinkedMultiValueMap<String, String>();

        if (StringUtils.isNotBlank(toPlace)) {
            map2.add("toPlace", toPlace);
        }
        if (toPlaceLng != null && toPlaceLng != 0) {
            map2.add("toPlaceLng", String.valueOf(toPlaceLng));
        }
        if (toPlaceLat != null && toPlaceLat != 0) {
            map2.add("toPlaceLat", String.valueOf(toPlaceLat));
        }

        map2.add("orderId", String.valueOf(orderId));
        map2.add("realCash", String.valueOf(realCash));
        map2.add("guoluMoney", String.valueOf(guoluMoney));
        map2.add("yuanchengMoney", String.valueOf(yuanchengMoney));
        map2.add("otherMoney", String.valueOf(otherMoney));
        map2.add("mileage", String.valueOf(mileage));
        map2.add("waitedTime", String.valueOf(waitedTime));
        map2.add("travelTime", String.valueOf(travelTime));
        map2.add("startPrice", String.valueOf(startPrice));
        map2.add("mileagePrice", String.valueOf(mileagePrice));
        map2.add("runTimePrice", String.valueOf(runTimePrice));
        if (waitPrice != null) {
            map2.add("waitPrice", String.valueOf(waitPrice));
        }
        map2.add("memo", memo);
        map2.add("xml", xml);

        try {

            RestTemplate rest = new RestTemplate();

            String result = rest.postForObject(buildApi(address, "api/zhuanche/confirmTask.json"), map2, String.class);

            JSONObject jsonObject = JSON.parseObject(result);
            Boolean success = jsonObject.getBoolean("success");
            if (success) {
                Map<String, Object> data = new HashMap<String, Object>();
                data.put("type", jsonObject.getString("type"));
                map.put("data", data);
                map.put("code", 0);
                map.put("msg", jsonObject.getString("message"));
            } else {
                map.put("code", -1);
                map.put("msg", jsonObject.getString("message"));
            }

        } catch (HttpClientErrorException ex) {
            map.put("code", -1);
            map.put("msg", ex.getResponseBodyAsString());
        } catch (HttpServerErrorException ex) {
            map.put("code", -1);
            map.put("msg", ex.getResponseBodyAsString());
        }

        return map;
    }

    /**
     * 确认专车订单费用V4.
     */

    public ResultTransport confirmTaskZhuanV4(String address, Long orderId, Double realCash, Double guoluMoney,
                                              Double yuanchengMoney, Double otherMoney, Double mileage, Integer waitedTime, Integer travelTime,
                                              String toPlace, Double toPlaceLng, Double toPlaceLat, Double startPrice, Double mileagePrice,
                                              Double runTimePrice, Double waitPrice, String memo, String jsonLocs, Double ksMileage, Double ddMileage,
                                              Double commission) {

        MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();

        if (StringUtils.isNotBlank(toPlace)) {
            map.add("toPlace", toPlace);
        }
        if (toPlaceLng != null && toPlaceLng != 0) {
            map.add("toPlaceLng", String.valueOf(toPlaceLng));
        }
        if (toPlaceLat != null && toPlaceLat != 0) {
            map.add("toPlaceLat", String.valueOf(toPlaceLat));
        }

        map.add("orderId", String.valueOf(orderId));
        map.add("realCash", String.valueOf(realCash));
        map.add("guoluMoney", String.valueOf(guoluMoney));
        map.add("yuanchengMoney", String.valueOf(yuanchengMoney));
        map.add("otherMoney", String.valueOf(otherMoney));
        map.add("mileage", String.valueOf(mileage));
        map.add("waitedTime", String.valueOf(waitedTime));
        map.add("travelTime", String.valueOf(travelTime));
        map.add("startPrice", String.valueOf(startPrice));
        map.add("mileagePrice", String.valueOf(mileagePrice));
        map.add("runTimePrice", String.valueOf(runTimePrice));
        if (waitPrice != null) {
            map.add("waitPrice", String.valueOf(waitPrice));
        }
        map.add("memo", memo);
        if (StringUtils.isNotBlank(jsonLocs)) {
            map.add("jsonLocs", jsonLocs);
        }
        if (null != ksMileage) {
            map.add("ksMileage", String.valueOf(ksMileage));
        }
        if (null != ddMileage) {
            map.add("ddMileage", String.valueOf(ddMileage));
        }
        if (null != commission) {
            map.add("commission", String.valueOf(commission));
        }
        RestTemplate rest = new RestTemplate();

        String result = rest.postForObject(buildApi(address, "api/zhuanche/v4/confirmTask.json"), map, String.class);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 请求专车支付宝支付接口.
     */
    public Map<String, Object> zhuanchealiPrepay(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/zhuanche/alipay/prepay.json?orderId={orderId}&orderType={orderType}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId, "zhuanche");
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            String url = jsonObject.getString("url");
            map.put("code", 0);
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("url", url);
            map.put("data", data);
            map.put("msg", "请求成功");
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 请求专车微信支付接口.
     */
    public Map<String, Object> zhuanchewxPrepay(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/zhuanche/wx/prepay.json?orderId={orderId}&orderType={orderType}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId, "zhuanche");
        JSONObject jsonObject = JSON.parseObject(result);

        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("appid", jsonObject.getString("appid"));
            data.put("noncestr", jsonObject.getString("noncestr"));
            data.put("package", jsonObject.getString("package"));
            data.put("partnerid", jsonObject.getString("partnerid"));
            data.put("prepayid", jsonObject.getString("prepayid"));
            data.put("timestamp", jsonObject.getString("timestamp"));
            data.put("sign", jsonObject.getString("sign"));

            map.put("data", data);
            map.put("msg", "请求成功");
        } else {
            map.put("code", -1);
            System.err.println(jsonObject.getString("message"));
            map.put("msg", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 专车订单新单推送.
     */
    public void pushCreate(String addressUrl, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(addressUrl, "api/zhuanche/pushNewOrder"));
        builder.append("?orderId={orderId}");
        restTemplate.getForObject(builder.toString(), String.class, orderId);
    }

    /**
     * 专车订单接单推送.
     */

    public void pushJiedan(String addressUrl, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(addressUrl, "api/zhuanche/acceptOrder"));
        builder.append("?orderId={orderId}");
        restTemplate.getForObject(builder.toString(), String.class, orderId);
    }

    /**
     * 专车接单推送.
     */

    public ResultTransport pushJiedanV4(String addressUrl, Long orderId, Long employId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(addressUrl, "api/zhuanche/v4/acceptOrder?orderId={orderId}&employId={employId}"));

        String result = restTemplate.getForObject(builder.toString(), String.class, orderId, employId);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 更新执行专车订单的司机状态为空闲.
     */

    public String updateDriver(String server, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/zhuanche/updateDriver?orderId={orderId}"));
        String response = restTemplate.getForObject(builder.toString(), String.class, orderId);
        return response;
    }

    /**
     * 保存拒单记录到代驾系统.
     */
    public String refuseOrder(String server, Long orderId, Long employId, String memo) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/zhuanche/refuseOrder?orderId={orderId}&employId={employId}&memo={memo}"));
        String response = restTemplate.getForObject(builder.toString(), String.class, orderId, employId, memo);
        return response;
    }

    /**
     * 专车拒单推送并保存在代驾项目拒单记录.
     */

    public ResultTransport refuseOrderV4(String server, Long orderId, Long employId, String memo) {
        StringBuilder builder = new StringBuilder();
        builder.append(
                buildApi(server, "api/zhuanche/v4/refuseOrder?orderId={orderId}&employId={employId}&memo={memo}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId, employId, memo);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 更新执行专车订单的司机状态为忙碌.
     */

    public String updateBusyDriver(String server, Long driverId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/zhuanche/updateBusyDriver?driverId={driverId}"));
        String response = restTemplate.getForObject(builder.toString(), String.class, driverId);
        return response;
    }

    /**
     * 专车订单销单推送.
     */

    public void pushCancel(String addressUrl, Long orderId, Long employId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(addressUrl, "api/zhuanche/cancelOrder"));
        builder.append("?orderId={orderId}&employId={employId}");
        restTemplate.getForObject(builder.toString(), String.class, orderId, employId);
    }

    /**
     * 专车到达预约地发送短信给客户.
     */

    public void pushWaitZhuan(String addressUrl, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(addressUrl, "api/zhuanche/pushWaitZhuan?orderId={orderId}"));
        restTemplate.getForObject(builder.toString(), String.class, orderId);
    }

    /**
     * 专车到达预约地推送.
     */

    public ResultTransport pushWaitZhuanV4(String addressUrl, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(addressUrl, "api/zhuanche/v4/pushWaitZhuan?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 推送给客户服务人员开始执行订单.
     */

    public void pushRunOrderZhuan(String address, Long orderId) {
        String url = buildApi(address, "api/zhuanche/pushRunOrder?orderId={orderId}");
        restTemplate.getForObject(url, String.class, orderId);
    }

    /**
     * 专车订单出发推送.
     */

    public ResultTransport pushRunOrderZhuanV4(String address, Long orderId) {
        String url = buildApi(address, "api/zhuanche/v4/pushRunOrder?orderId={orderId}");
        String result = restTemplate.getForObject(url, String.class, orderId);
        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 查询附近货运司机.
     */

    public Map<String, Object> findDrivers(String server, Double lng, Double lat, Long truckTypeId) {
        Map<String, Object> map = new HashMap<String, Object>();

        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/freight/findDrivers"));
        builder.append("?lng={lng}&lat={lat}&truckTypeId={truckTypeId}");
        String string = restTemplate.getForObject(builder.toString(), String.class, lng, lat, truckTypeId);
        JSONObject jsonObject = JSON.parseObject(string);
        int code = jsonObject.getIntValue("code");
        map.put("code", code);
        map.put("msg", jsonObject.getString("message"));
        if (code == 0) {
            JSONArray data = jsonObject.getJSONArray("data");
            List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
            if (data != null) {
                for (int i = 0; i < data.size(); i++) {
                    JSONObject object = data.getJSONObject(i);

                    Map<String, Object> employee = new HashMap<String, Object>();
                    try {
                        Double carlat = object.getDouble("lat");
                        employee.put("driverLat", carlat);
                    } catch (Exception ex) {
                        logger.error(ex.getMessage());
                    }
                    try {
                        Double carlng = object.getDouble("lng");
                        employee.put("driverLng", carlng);
                    } catch (Exception ex) {
                        logger.error(ex.getMessage());
                    }
                    String address = object.getString("address");
                    String carNumber = object.getString("carNumber");
                    employee.put("address", address);
                    employee.put("carNumber", carNumber);

                    list.add(employee);
                }
            }
            map.put("data", list);
        }
        return map;
    }

    /**
     * 查询附近货运车辆类型.
     */

    public @ResponseBody
    Map<String, Object> findTruckType(String server, String acKey, Double lng, Double lat) {
        Map<String, Object> map = new HashMap<String, Object>();

        StringBuilder builder = new StringBuilder();

        builder.append(buildApi(server, "api/freight/findTruckType"));
        builder.append("?acKey={acKey}&lng={lng}&lat={lat}");

        String result = restTemplate.getForObject(builder.toString(), String.class, acKey, lng, lat);

        JSONObject jo = JSON.parseObject(result);
        int code = jo.getIntValue("code");
        map.put("code", code);
        String message = jo.getString("message");
        map.put("msg", message);
        if (code == 0) {
            JSONArray list = jo.getJSONArray("data");
            List<TruckType> data = JSON.parseArray(list.toString(), TruckType.class);
            map.put("data", data);
        }
        return map;
    }

    /**
     * 查询货运车型.
     */

    public @ResponseBody
    Map<String, Object> queryTruckType(String server, Long companyId) {
        Map<String, Object> map = new HashMap<String, Object>();

        String result = restTemplate.getForObject(buildApi(server, "api/freight/queryTruckType?companyId={companyId}"),
                String.class, companyId);
        JSONObject jo = JSON.parseObject(result);
        int code = jo.getIntValue("code");
        map.put("code", code);
        String message = jo.getString("message");
        map.put("msg", message);
        if (code == 0) {
            JSONArray list = jo.getJSONArray("data");
            List<TruckType> data = JSON.parseArray(list.toString(), TruckType.class);
            map.put("data", data);
        }
        return map;
    }

    /**
     * 查询货车位置(实际为驾驶该货车车辆的司机位置).
     */

    public @ResponseBody
    Map<String, Object> queryFreightCar(String server, Long driverId) {
        Map<String, Object> map = new HashMap<String, Object>();

        StringBuilder builder = new StringBuilder();

        builder.append(buildApi(server, "api/freight/findDriverById"));
        builder.append("?driverId={driverId}");

        String result = restTemplate.getForObject(builder.toString(), String.class, driverId);
        JSONObject jsonObject = JSON.parseObject(result);
        int code = jsonObject.getIntValue("code");
        map.put("code", code);
        map.put("msg", jsonObject.getString("message"));
        if (code == 0) {
            JSONObject data = jsonObject.getJSONObject("data");
            if (data != null) {
                Map<String, Object> employee = new HashMap<String, Object>();

                Double lng = data.getDouble("lng");
                String address = data.getString("address");
                String carNumber = data.getString("carNumber");
                Double lat = data.getDouble("lat");
                String employNo = data.getString("employNo");
                Double employScore = data.getDouble("employScore");
                employee.put("Lng", lng);
                employee.put("Lat", lat);
                employee.put("address", address);
                employee.put("carNumber", carNumber);
                employee.put("employNo", employNo);
                employee.put("employScore", employScore);

                map.put("data", employee);
            }
        }
        return map;
    }

    /**
     * 推送货运新单.
     */

    public String pushFreightNewOrder(String server, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/freight/pushNewOrder"));
        builder.append("?orderId={orderId}");
        String response = restTemplate.getForObject(builder.toString(), String.class, orderId);

        return response;
    }

    /**
     * 接单推送.
     */

    public void pushOrderAccept(String server, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/freight/pushOrderAccept"));
        builder.append("?orderId={orderId}");
        restTemplate.getForObject(builder.toString(), String.class, orderId);
    }

    /**
     * 货运订单推送到达预约地.
     */

    public ResultTransport pushOrderAcceptV4(String server, Long orderId, Long employId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/freight/v4/pushOrderAccept?orderId={orderId}&employId={employId}"));

        String result = restTemplate.getForObject(builder.toString(), String.class, orderId, employId);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 货运到达预约地推送.
     */

    public void pushWait(String server, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/freight/pushWait"));
        builder.append("?orderId={orderId}");
        restTemplate.getForObject(builder.toString(), String.class, orderId);
    }

    /**
     * 货运订单开始到达预约地开始等待.
     */

    public ResultTransport pushWaitV4(String server, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/freight/v4/pushWait?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 货运拒单推送.
     */

    public void pushRefuseFreight(String server, Long orderId, Long employId, String cause) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/freight/pushRefuseOrder"));
        builder.append("?orderId={orderId}&employId={employId}&cause={cause}");
        restTemplate.getForObject(builder.toString(), String.class, orderId, employId, cause);
    }

    /**
     * 货运拒单推送.
     */

    public ResultTransport pushRefuseFreightV4(String server, Long orderId, Long employId, String cause) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/freight/v4/pushRefuseOrder"));
        builder.append("?orderId={orderId}&employId={employId}&cause={cause}");
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId, employId, cause);
        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);
        return resultTransport;
    }

    /**
     * 原跑腿拒单推送到后台,后台处理:(更新服务人员状态).
     */

    public void pushRefuseOrder(String server, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/errand/pushRefuseOrder"));
        builder.append("?orderId={orderId}");
        restTemplate.getForObject(builder.toString(), String.class, orderId);
    }

    /**
     * V2跑腿拒单推送到后台,后台处理:(更新服务人员状态).
     */

    public void pushRefuseErrand(String server, Long orderId, Long employId, String content) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/errand/pushRefuseOrder"));
        builder.append("?orderId={orderId}&employId={employId}&content={content}");
        restTemplate.getForObject(builder.toString(), String.class, orderId, employId, content);
    }

    /**
     * 跑腿拒单推送.
     */

    public ResultTransport pushRefuseErrandV4(String server, Long orderId, Long employId, String content) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/errand/v4/pushRefuseOrder"));
        builder.append("?orderId={orderId}&employId={employId}&content={content}");
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId, employId, content);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 销单推送.
     */

    public void pushOrderCancel(String server, Long orderId, boolean isDriver) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/freight/pushOrderCancel"));
        builder.append("?orderId={orderId}&isDriver={isDriver}");
        restTemplate.getForObject(builder.toString(), String.class, orderId, isDriver);
    }

    /**
     * 货运销单推送.
     */

    public ResultTransport pushOrderCancelV4(String server, Long orderId, boolean isDriver, String cause) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/freight/v4/pushOrderCancel"));
        builder.append("?orderId={orderId}&isDriver={isDriver}&cause={cause}");
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId, isDriver, cause);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * 货运订单结算接口.
     */

    public @ResponseBody
    Map<String, Object> confirmTaskFreight(String address, Long orderId, Double realCash,
                                           Double guoluMoney, Double yuanchengMoney, Double otherMoney, Double mileage, Integer waitedTime,
                                           Integer travelTime, String xml, Double startPrice, Double mileagePrice, Double runTimePrice,
                                           Double waitPrice, String memo) {

        Map<String, Object> map = new HashMap<String, Object>();

        MultiValueMap<String, String> map2 = new LinkedMultiValueMap<String, String>();

        map2.add("orderId", String.valueOf(orderId));
        map2.add("realCash", String.valueOf(realCash));
        map2.add("guoluMoney", String.valueOf(guoluMoney));
        map2.add("yuanchengMoney", String.valueOf(yuanchengMoney));
        map2.add("otherMoney", String.valueOf(otherMoney));
        map2.add("mileage", String.valueOf(mileage));
        map2.add("waitedTime", String.valueOf(waitedTime));
        map2.add("travelTime", String.valueOf(travelTime));
        map2.add("startPrice", String.valueOf(startPrice));
        map2.add("mileagePrice", String.valueOf(mileagePrice));
        map2.add("runTimePrice", String.valueOf(runTimePrice));
        if (waitPrice != null) {
            map2.add("waitPrice", String.valueOf(waitPrice));
        }
        map2.add("memo", memo);
        map2.add("xml", xml);
        try {
            RestTemplate rest = new RestTemplate();

            String result = rest.postForObject(buildApi(address, "api/freight/confirmTask.json"), map2, String.class);

            JSONObject jsonObject = JSON.parseObject(result);
            Boolean success = jsonObject.getBoolean("success");
            if (success) {
                Map<String, Object> data = new HashMap<String, Object>();
                data.put("type", jsonObject.getString("type"));
                map.put("data", data);
                map.put("code", 0);
                map.put("msg", jsonObject.getString("message"));
            } else {
                map.put("code", -1);
                map.put("msg", jsonObject.getString("message"));
            }

        } catch (HttpClientErrorException ex) {
            map.put("code", -1);
            map.put("msg", ex.getResponseBodyAsString());
        } catch (HttpServerErrorException ex) {
            map.put("code", -1);
            map.put("msg", ex.getResponseBodyAsString());
        }

        return map;
    }

    /**
     * 货运订单确认费用.
     */

    public ResultTransport confirmTaskFreightV4(String address, Long orderId, Double realCash, Double guoluMoney,
                                                Double yuanchengMoney, Double otherMoney, Double mileage, Integer waitedTime, Integer travelTime,
                                                Double startPrice, Double mileagePrice, Double runTimePrice, Double waitPrice, String memo,
                                                String jsonLocs) {
        MultiValueMap<String, String> map2 = new LinkedMultiValueMap<String, String>();

        map2.add("orderId", String.valueOf(orderId));
        map2.add("realCash", String.valueOf(realCash));
        map2.add("guoluMoney", String.valueOf(guoluMoney));
        map2.add("yuanchengMoney", String.valueOf(yuanchengMoney));
        map2.add("otherMoney", String.valueOf(otherMoney));
        map2.add("mileage", String.valueOf(mileage));
        map2.add("waitedTime", String.valueOf(waitedTime));
        map2.add("travelTime", String.valueOf(travelTime));
        map2.add("startPrice", String.valueOf(startPrice));
        map2.add("mileagePrice", String.valueOf(mileagePrice));
        map2.add("runTimePrice", String.valueOf(runTimePrice));
        if (waitPrice != null) {
            map2.add("waitPrice", String.valueOf(waitPrice));
        }
        map2.add("memo", memo);
        if (StringUtils.isNotBlank(jsonLocs)) {
            map2.add("jsonLocs", jsonLocs);
        }
        RestTemplate rest = new RestTemplate();

        String result = rest.postForObject(buildApi(address, "api/freight/v4/confirmTask.json"), map2, String.class);

        ResultTransport parseObject = JSON.parseObject(result, ResultTransport.class);

        return parseObject;
    }

    /**
     * 货运订单结算页面的数据.
     */

    public @ResponseBody
    Map<String, Object> completeTaskFreight(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/freight/completeTaskData.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("id", jsonObject.getLong("orderId"));
            data.put("orderNumber", jsonObject.getString("orderNumber"));
            data.put("orderType", jsonObject.getString("orderType"));
            data.put("passengerPhone", jsonObject.getString("passengerPhone"));
            data.put("passengerName", jsonObject.getString("passengerName"));
            data.put("passengerType", jsonObject.getString("passengerType"));
            data.put("orderCompanyName", jsonObject.getString("orderCompanyName"));
            data.put("passengerCompanyName", jsonObject.getString("passengerCompanyName"));
            data.put("overdraw", jsonObject.getBoolean("overdraw"));
            data.put("virtual", jsonObject.getString("virtual"));
            try {
                data.put("couponMoney", jsonObject.getDouble("couponMoney"));
            } catch (Exception ex) {
                data.put("couponMoney", null);
            }
            try {
                data.put("discount", jsonObject.getDouble("discount"));
            } catch (Exception ex) {
                data.put("discount", null);
            }
            data.put("employId", jsonObject.getLong("employId"));
            data.put("employName", jsonObject.getString("employName"));
            data.put("employPhone", jsonObject.getString("employPhone"));
            map.put("data", data);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 货运确认费用V4.
     */

    public ResultTransport completeTaskFreightV4(String address, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/freight/v4/completeTaskData.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        ResultTransport parseObject = JSON.parseObject(result, ResultTransport.class);

        return parseObject;
    }

    /**
     * 实时获取货运订单是否被结算.
     */
    public @ResponseBody
    Map<String, Object> checkTaskFreight(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/freight/checkTask.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("data", jsonObject.getBoolean("finished"));
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 实时检测货运订单是否被结算V4.
     */

    public ResultTransport checkTaskFreightV4(String address, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/freight/v4/checkTask.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        ResultTransport parseObject = JSON.parseObject(result, ResultTransport.class);

        return parseObject;
    }

    /**
     * 货运完成结算接口.
     */

    public @ResponseBody
    Map<String, Object> finishTaskFreight(String address, Long orderId, String payType) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/freight/finishTask.json?orderId={orderId}&payType={payType}"));
        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.put("orderId", orderId);
        map2.put("payType", payType);
        String result = restTemplate.postForObject(builder.toString(), null, String.class, map2);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("msg", jsonObject.getString("message"));
            map.put("data", null);
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 完成货运订单V4.
     */

    public ResultTransport finishTaskFreightV4(String address, Long orderId, String payType, String who) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/freight/v4/finishTask.json?orderId={orderId}&payType={payType}"));
        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.put("orderId", orderId);
        map2.put("payType", payType);
        if (StringUtils.isNotBlank(who)) {
            builder.append("&who={who}");
            map2.put("who", who);
        }
        String result = restTemplate.postForObject(builder.toString(), null, String.class, map2);
        ResultTransport parseObject = JSON.parseObject(result, ResultTransport.class);

        return parseObject;
    }

    /**
     * 货运订单客户端支付所需数据.
     */

    public @ResponseBody
    Map<String, Object> clientPayDataFreight(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/freight/clientPayData.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("id", orderId);
            data.put("realCash", jsonObject.getDouble("realCash"));
            data.put("guoluMoney", jsonObject.getDouble("guoluMoney"));
            data.put("yuanchengMoney", jsonObject.getDouble("yuanchengMoney"));
            data.put("otherMoney", jsonObject.getDouble("otherMoney"));
            data.put("payMoney", jsonObject.getDouble("payMoney"));
            data.put("weixinPay", jsonObject.getBoolean("weixinPay"));
            data.put("aliPay", jsonObject.getBoolean("aliPay"));
            try {
                data.put("unionPay", jsonObject.getBoolean("unionPay"));
            } catch (Exception e) {
                data.put("unionPay", Boolean.FALSE);
            }
            data.put("overdraw", jsonObject.getBoolean("overdraw"));
            try {
                data.put("couponMoney", jsonObject.getDouble("couponMoney"));
            } catch (Exception ex) {
                logger.error(ex.getMessage());
            }
            map.put("data", data);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 客户端支付宝结算货运订单.
     */

    public @ResponseBody
    Map<String, Object> aliAfterpayFreight(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/freight/alipay/afterpay.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Map<String, Object> data = new HashMap<String, Object>();
            String url = jsonObject.getString("url");
            data.put("url", url);
            map.put("data", data);
            map.put("code", 0);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 客户端微信结算货运订单.
     */

    public @ResponseBody
    Map<String, Object> wxAfterpayFreight(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/freight/wx/afterpay.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("appid", jsonObject.getString("appid"));
            data.put("noncestr", jsonObject.getString("noncestr"));
            data.put("package", jsonObject.getString("package"));
            data.put("partnerid", jsonObject.getString("partnerid"));
            data.put("prepayid", jsonObject.getString("prepayid"));
            data.put("timestamp", jsonObject.getString("timestamp"));
            data.put("sign", jsonObject.getString("sign"));
            map.put("data", data);
            map.put("code", 0);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 上传图片文件到代驾项目.
     */

    public String uploadImg(String server, Long orderId, String imgUrl) {
        String imgurl = "";
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/errand/uploadErrandImg?orderId={orderId}&imgUrl={imgUrl}"));
        try {
            String result = restTemplate.getForObject(builder.toString(), String.class, orderId, imgUrl);
            if (StringUtils.isNotBlank(result)) {
                JSONObject object = JSON.parseObject(result);
                Integer code = object.getInteger("code");
                if (code == 0) {
                    JSONObject data = object.getJSONObject("data");
                    imgurl = data.getString("imgurl");
                }
            }
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return imgurl;
        }

        return imgurl;
    }

    /**
     * 推送到司机端的.
     */

    public String pushDriver(String server, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/errand/pushCancelOrder"));
        builder.append("?orderId={orderId}");
        String response = restTemplate.getForObject(builder.toString(), String.class, orderId);
        return response;
    }

    /**
     * 跑腿订单销单推送.
     */

    public ResultTransport pushDriverV4(String server, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/errand/v4/pushCancelOrder?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        ResultTransport transport = JSON.parseObject(result, ResultTransport.class);
        return transport;
    }

    /**
     * 执行跑腿订单推送到客户端.
     */

    public String pushRunOrder(String address, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/errand/pushRunOrder"));
        builder.append("?orderId={orderId}");
        String response = restTemplate.getForObject(builder.toString(), String.class, orderId);
        return response;
    }

    /**
     * 跑腿订单出发推送V4.
     */

    public ResultTransport pushRunOrderV4(String address, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/errand/v4/pushRunOrder?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);
        return resultTransport;
    }

    /**
     * 下单推送到后台管理系统.
     */

    public String pushNewOrder(String server, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, "api/errand/pushNewOrder"));
        builder.append("?orderId={orderId}");
        String response = restTemplate.getForObject(builder.toString(), String.class, orderId);

        return response;
    }

    /**
     * 预算跑腿订单价格.
     */

    public JSONObject getErrandPrice(String server, Long passengerId, String city, String acKey, Double startLat,
                                     Double startLng, Double endLat, Double endLng) {
        String result = restTemplate.getForObject(buildApi(server, GET_ERRAND_PRICE), String.class, passengerId, city,
                acKey, startLat, startLng, endLat, endLng);
        JSONObject jsonObject = JSON.parseObject(result);
        return jsonObject;
    }

    /**
     * 跑腿订单新单.
     */

    public JSONObject getErrandNewPrice(String server, Long passengerId, String city, String acKey, Integer time,
                                        Double mileage) {
        String result = restTemplate.getForObject(buildApi(server, GET_ERRAND_NEW_PRICE), String.class, passengerId,
                city, acKey, time, mileage);
        JSONObject jsonObject = JSON.parseObject(result);
        return jsonObject;
    }

    /**
     * 补单预算费用.
     */

    public @ResponseBody
    Map<String, Object> getPriceByAreaId(String server, Long areaId, Double startLat,
                                         Double startLng, Double endLat, Double endLng) {

        String url = buildApi(server, GET_PRICE_BY_AREAID);
        Map<String, String> kv = new HashMap<String, String>();
        kv.put("areaId", String.valueOf(areaId));
        kv.put("startLat", String.valueOf(startLat));
        kv.put("startLng", String.valueOf(startLng));
        if (endLat != null && endLat != 0 && endLng != null && endLng != 0) {
            url += "&endLat={endLat}&endLng={endLng}";
            kv.put("endLat", String.valueOf(endLat));
            kv.put("endLng", String.valueOf(endLng));
        }
        String result = restTemplate.getForObject(url, String.class, kv);
        JSONObject jsonObject = JSON.parseObject(result);
        Integer code = jsonObject.getInteger("code");
        Double money = 0.0;
        Double mileage = 0.0;
        Integer travelTime = 0;
        Double startPrice = 0.0;
        Double mileagePrice = 0.0;
        Double travelTimePrice = 0.0;
        String payDetail = "";
        if (code == 0) {
            JSONObject data = jsonObject.getJSONObject("data");
            money = data.getDouble("money");
            mileage = data.getDouble("mileage");
            travelTime = data.getInteger("time");
            startPrice = data.getDouble("startPrice");
            mileagePrice = data.getDouble("mileagePrice");
            travelTimePrice = data.getDouble("travelTimePrice");
            payDetail = data.getString("pay_detail");
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("money", money);
        map.put("mileage", mileage);
        map.put("travelTime", travelTime);
        map.put("startPrice", startPrice);
        map.put("mileagePrice", mileagePrice);
        map.put("travelTimePrice", travelTimePrice);
        map.put("pay_detail", payDetail);
        return map;
    }

    /**
     * 根据areaId,经纬度预估跑腿费用V4.
     */

    public ResultTransport getPriceByAreaIdV4(String server, Long areaId, Double startLat, Double startLng,
                                              Double endLat, Double endLng) {
        String url = buildApi(server, GET_PRICE_BY_AREAID_V4);
        Map<String, String> kv = new HashMap<String, String>();
        kv.put("areaId", String.valueOf(areaId));
        kv.put("startLat", String.valueOf(startLat));
        kv.put("startLng", String.valueOf(startLng));
        if (endLat != null && endLat != 0 && endLng != null && endLng != 0) {
            url += "&endLat={endLat}&endLng={endLng}";
            kv.put("endLat", String.valueOf(endLat));
            kv.put("endLng", String.valueOf(endLng));
        }

        String result = restTemplate.getForObject(url, String.class, kv);
        ResultTransport transport = JSON.parseObject(result, ResultTransport.class);

        return transport;
    }

    /**
     * V4根据areaId,时间,距离预算费用.
     */

    public ResultTransport getPriceByTimeAndMileageV4(String server, Long areaId, Integer time, Double mileage, Double weight) {
        Map<String, String> kv = new HashMap<String, String>();
        kv.put("areaId", String.valueOf(areaId));
        kv.put("time", String.valueOf(time));
        kv.put("mileage", String.valueOf(mileage));

        if (null == weight) {
            weight = 0D;
        }

        kv.put("weight", String.valueOf(weight));

        String result = restTemplate.getForObject(buildApi(server, GET_PRICE_BY_TIME_MILEAGE_V4), String.class, kv);
        ResultTransport transport = JSON.parseObject(result, ResultTransport.class);

        return transport;
    }

    /**
     * 获取收费标准.
     *
     * @param areaId 收费标准id
     */

    public Area queryArea(String server, Long areaId) {
        Area area = new Area();

        String result = restTemplate.getForObject(buildApi(server, QUERY_AREA), String.class, areaId);

        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            JSONObject data = jsonObject.getJSONObject("data");
            area = JSON.parseObject(data.toString(), Area.class);
        }

        return area;
    }

    /**
     * 接单推送到后台管理系统.
     */

    public void pushAcceptOrder(String address, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/errand/pushAcceptOrder"));
        builder.append("?orderId={orderId}");
        restTemplate.getForObject(builder.toString(), String.class, orderId);
    }

    /**
     * 跑腿订单到达预约地V4.
     */

    public ResultTransport pushAcceptOrderV4(String address, Long orderId, Long employId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/errand/v4/pushAcceptOrder?orderId={orderId}&employId={employId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId, employId);

        ResultTransport resultTransport = JSON.parseObject(result, ResultTransport.class);

        return resultTransport;
    }

    /**
     * V2实时获取跑腿订单是否被结算.
     */
    public Map<String, Object> checkTaskErrand(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/errand/checkTask.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("data", jsonObject.getBoolean("finished"));
            map.put("msg", "成功");
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 实时检测跑腿订单是否被结算.
     */

    public ResultTransport checkTaskErrandV4(String address, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/errand/v4/checkTask.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        ResultTransport parseObject = JSON.parseObject(result, ResultTransport.class);

        return parseObject;
    }

    /**
     * V2支付宝支付跑腿订单.
     */

    public Map<String, Object> aliAfterpayErrand(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/errand/alipay/afterpay.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Map<String, Object> data = new HashMap<String, Object>();
            String url = jsonObject.getString("url");
            data.put("url", url);
            map.put("data", data);
            map.put("code", 0);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 客户端微信结算专车订单.
     */

    public Map<String, Object> wxAfterpayErrand(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/errand/wx/afterpay.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("appid", jsonObject.getString("appid"));
            data.put("noncestr", jsonObject.getString("noncestr"));
            data.put("package", jsonObject.getString("package"));
            data.put("partnerid", jsonObject.getString("partnerid"));
            data.put("prepayid", jsonObject.getString("prepayid"));
            data.put("timestamp", jsonObject.getString("timestamp"));
            data.put("sign", jsonObject.getString("sign"));
            map.put("data", data);
            map.put("code", 0);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * V2跑腿订单客户端支付所需数据.
     */

    public Map<String, Object> clientPayDataErrand(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/errand/clientPayData.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("id", orderId);
            data.put("realCash", jsonObject.getDouble("realCash"));
            data.put("guoluMoney", jsonObject.getDouble("guoluMoney"));
            data.put("yuanchengMoney", jsonObject.getDouble("yuanchengMoney"));
            data.put("otherMoney", jsonObject.getDouble("otherMoney"));
            data.put("preyMoney", jsonObject.getDouble("preyMoney"));
            data.put("couponMoney", jsonObject.getDouble("couponMoney"));
            data.put("payMoney", jsonObject.getDouble("payMoney"));
            data.put("weixinPay", jsonObject.getBoolean("weixinPay"));
            data.put("aliPay", jsonObject.getBoolean("aliPay"));
            try {
                data.put("unionPay", jsonObject.getBoolean("unionPay"));
            } catch (Exception e) {
                data.put("unionPay", Boolean.FALSE);
            }
            data.put("overdraw", jsonObject.getBoolean("overdraw"));
            data.put("goodsCash", jsonObject.getDouble("goodsCash"));
            data.put("thanksCash", jsonObject.getDouble("thanksCash"));

            //增加重量收费显示
            try {
                data.put("weightPrice", jsonObject.getDouble("weightPrice"));
            } catch (Exception e) {
                data.put("weightPrice", 0D);
            }

            map.put("data", data);
            map.put("msg", jsonObject.getString("message"));
        } else {
            map.put("code", -4);
            map.put("msg", jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 跑腿完成结算.
     */

    public Map<String, Object> finishTaskErrand(String address, Long orderId, String payType, String who) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/errand/finishTask.json?orderId={orderId}&payType={payType}"));
        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.put("orderId", orderId);
        map2.put("payType", payType);
        if (StringUtils.isNotBlank(who)) {
            builder.append("&who={who}");
            map2.put("who", who);
        }
        String result = restTemplate.postForObject(builder.toString(), null, String.class, map2);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            map.put("msg", jsonObject.getString("message"));
            map.put("data", null);
        } else {
            map.put("code", -1);
            map.put("msg", jsonObject.getString("message"));
            System.err.println(jsonObject.getString("message"));
        }
        return map;
    }

    /**
     * 跑腿完成订单V4.
     */

    public ResultTransport finishTaskErrandV4(String address, Long orderId, String payType, String who) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/errand/v4/finishTask.json?orderId={orderId}&payType={payType}"));
        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.put("orderId", orderId);
        map2.put("payType", payType);
        if (StringUtils.isNotBlank(who)) {
            map2.put("who", who);
            builder.append("&who={who}");
        }
        String result = restTemplate.postForObject(builder.toString(), null, String.class, map2);
        ResultTransport parseObject = JSON.parseObject(result, ResultTransport.class);

        return parseObject;
    }

    /**
     * 跑腿订单结算页面的数据.
     */

    public Map<String, Object> completeTaskErrand(String address, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/errand/completeTaskData.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        JSONObject jsonObject = JSON.parseObject(result);
        Boolean success = jsonObject.getBoolean("success");
        if (success) {
            map.put("code", 0);
            Map<String, Object> data = new HashMap<String, Object>();
            data.put("id", jsonObject.getLong("orderId"));
            data.put("orderNumber", jsonObject.getString("orderNumber"));
            data.put("orderType", jsonObject.getString("orderType"));
            data.put("passengerPhone", jsonObject.getString("passengerPhone"));
            data.put("passengerName", jsonObject.getString("passengerName"));
            data.put("passengerType", jsonObject.getString("passengerType"));
            data.put("orderCompanyName", jsonObject.getString("orderCompanyName"));
            data.put("passengerCompanyName", jsonObject.getString("passengerCompanyName"));
            data.put("overdraw", jsonObject.getBoolean("overdraw"));
            data.put("virtual", jsonObject.getString("virtual"));
            try {
                data.put("couponMoney", jsonObject.getDouble("couponMoney"));
            } catch (Exception ex) {
                data.put("couponMoney", null);
            }
            try {
                data.put("discount", jsonObject.getDouble("discount"));
            } catch (Exception ex) {
                data.put("discount", null);
            }
            data.put("preyMoney", jsonObject.getDouble("preyMoney"));
            data.put("employId", jsonObject.getLong("employId"));
            data.put("employName", jsonObject.getString("employName"));
            data.put("employPhone", jsonObject.getString("employPhone"));
            map.put("data", data);
        } else {
            map.put("code", -1);
            System.err.println(jsonObject.getString("message"));
        }
        map.put("msg", jsonObject.getString("message"));
        return map;
    }

    /**
     * 跑腿确认费用V4.
     */

    public ResultTransport completeTaskErrandV4(String address, Long orderId) {
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(address, "api/errand/v4/completeTaskData.json?orderId={orderId}"));
        String result = restTemplate.getForObject(builder.toString(), String.class, orderId);
        ResultTransport parseObject = JSON.parseObject(result, ResultTransport.class);

        return parseObject;
    }

    /**
     * 查询服务协议.
     */

    public String getAgreement(String server) throws Exception {
        Document document = Jsoup.connect(buildApi(server, "member/api/rest/v3/agreement")).get();
        Element body = document.body();
        return body.html();
    }

    /**
     * V2筛选公司.
     *
     * @param server    系统地址
     * @param acKey     客户端区分公司 (选填)
     * @param companyId 客户所在公司id (选填)
     * @param longitude 客户当前位置经度 (选填)
     * @param latitude  客户当前位置纬度 (选填)
     */

    public JSONObject getCompany(String server, String acKey, Long companyId, Double longitude, Double latitude) {
        Map<String, String> kv = new HashMap<String, String>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, GET_COMPANY));
        if (StringUtils.isNotBlank(acKey)) {
            kv.put("acKey", acKey);
            builder.append("&acKey={acKey}");
        }
        if (companyId != null) {
            kv.put("companyId", String.valueOf(companyId));
            builder.append("&companyId={companyId}");
        }
        if (longitude != null && latitude != null) {
            kv.put("longitude", String.valueOf(longitude));
            kv.put("latitude", String.valueOf(latitude));
            builder.append("&longitude={longitude}&latitude={latitude}");
        }
        String url = builder.toString();
        if (!url.contains("?") && url.contains("&")) {
            url = url.replaceFirst("&", "?");
        }
        String response = restTemplate.getForObject(url, String.class, kv);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 查询附近跑腿司机.
     */

    public JSONObject queryErrandDriver(String server, Long companyId, Double distance, Double longitude,
                                        Double latitude) {
        Map<String, String> kv = new HashMap<String, String>();
        StringBuilder builder = new StringBuilder();
        builder.append(buildApi(server, QUERY_ERRAND_DRIVER));
        kv.put("lng", String.valueOf(longitude));
        kv.put("lat", String.valueOf(latitude));
        if (companyId != null) {
            kv.put("companyId", String.valueOf(companyId));
            builder.append("&companyId={companyId}");
        }
        if (distance != null) {
            kv.put("scope", String.valueOf(distance));
            builder.append("&scope={scope}");
        }
        String response = restTemplate.getForObject(builder.toString(), String.class, kv);

        JSONObject jsonObject = JSON.parseObject(response);

        return jsonObject;
    }

    /**
     * 查询未支付订单数量.
     */

    public Long countNotPayAmounts(String server, Long passengerId) {
        Long num = 0L;
        try {
            Map<String, String> kv = new HashMap<String, String>();
            StringBuilder builder = new StringBuilder();// 还有未完成支付的订单，不能下单
            builder.append(buildApi(server, COUNT_NOTPAYAMOUNTS));
            kv.put("passengerId", String.valueOf(passengerId));

            String response = restTemplate.getForObject(builder.toString(), String.class, kv);

            JSONObject jsonObject = JSON.parseObject(response);
            boolean bool = jsonObject.getBooleanValue("success");
            if (bool) {
                num = jsonObject.getLongValue("data");
            }
        } catch (Exception ex) {
            logger.error(ex.getMessage());
        }

        return num;
    }

    /**
     * 查询收费标准V4.
     */

    public ResultTransport findChargeStartTimes(String server, Long areaId) {
        String result = restTemplate.getForObject(buildApi(server, QUERY_CHARGESTARTTIMES), String.class, areaId);

        ResultTransport parseObject = JSON.parseObject(result, ResultTransport.class);

        return parseObject;
    }

    /**
     * 查询单个司机V4.
     */

    public ResultTransport findDriverV4(String server, Long employId) {
        String result = restTemplate.getForObject(buildApi(server, QUERY_ONE_DRIVER_V4), String.class, employId);

        ResultTransport parseObject = JSON.parseObject(result, ResultTransport.class);

        return parseObject;
    }

    /**
     * app根据token查询司机V4. employJobType:daijia,zhuanche,paotui,freight
     * employStatus:0:未上班,1:空闲(在线),2:接单,3:忙碌. employJobStatus:0代驾 1专车 2跑腿 3货运 -1无任务
     */

    public ResultTransport findDriverV4Token(String server, String employToken) {
        String result = restTemplate.getForObject(buildApi(server, QUERY_ONE_DRIVER_V4_TOKEN), String.class,
                employToken);

        ResultTransport parseObject = JSON.parseObject(result, ResultTransport.class);

        return parseObject;
    }

    /**
     * app根据token查询司机V5. employJobType:daijia,zhuanche,paotui,freight
     * employStatus:0:未上班,1:空闲(在线),2:接单,3:忙碌. employJobStatus:0代驾 1专车 2跑腿 3货运 -1无任务
     */

    public ResultV5 findDriverV5Token(String server, String employToken) {
        String result = restTemplate.getForObject(buildApi(server, QUERY_ONE_DRIVER_V4_TOKEN), String.class,
                employToken);

        ResultV5 parseObject = JSON.parseObject(result, ResultV5.class);

        return parseObject;
    }

    /**
     * 微信广告.
     */

    public JSONObject getAdvertisement(String server, Long companyId) {
        try {
            Map<String, String> kv = new HashMap<String, String>();
            StringBuilder builder = new StringBuilder();
            builder.append(buildApi(server, ADVERTISEMENT));
            kv.put("companyId", String.valueOf(companyId));

            String response = restTemplate.getForObject(builder.toString(), String.class, kv);
            JSONObject jsonObject = JSON.parseObject(response);

            return jsonObject;
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return null;
        }
    }

    /**
     * 构建Api地址.
     */

    private String buildApi(String server, String api) {
        StringBuilder builder = new StringBuilder();

        String daijiaServer = StringUtils.trimToEmpty(server).toLowerCase();
        /**如果server是www.scezu.com 用https协议*/
        if (daijiaServer.startsWith("www")) {
            builder.append("https://");
        } else if (!daijiaServer.startsWith("http://")) {
            builder.append("http://");
        }
        builder.append(daijiaServer);
        if (!daijiaServer.endsWith("/")) {
            builder.append("/");
        }

        if (StringUtils.isNotBlank(api)) {
            builder.append(api);
        }

        return builder.toString();
    }

    /**
     * 查询制指定客户正在执行中的代驾订单数量.
     */

    public JSONArray findRunning(String server, Long passengerId) {

        Map<String, String> kv = new HashMap<String, String>();
        kv.put("passengerId", String.valueOf(passengerId));

        String result = restTemplate.getForObject(buildApi(server, FIND_RUNNING), String.class, kv);
        JSONObject object = JSON.parseObject(result);
        JSONArray json = object.getJSONArray("data");
        return json;
    }

    /**
     * V5获取未完成订单
     *
     * @param server
     * @param passengerId
     * @return
     */
    public JSONArray findRunningV5(String server, Long passengerId) {

        Map<String, String> kv = new HashMap<String, String>();
        kv.put("passengerId", String.valueOf(passengerId));

        String result = restTemplate.getForObject(buildApi(server, FIND_RUNNING_V5), String.class, kv);
        JSONObject object = JSON.parseObject(result);
        JSONArray json = object.getJSONArray("data");
        return json;
    }

    public ResultVo balancesignPayCheck(String server, Double shouldPay, Long passengerId, String payType,
                                        Long couponId) {

        Map<String, String> kv = new HashMap<String, String>();
        kv.put("money", String.valueOf(shouldPay));
        kv.put("passengerId", String.valueOf(passengerId));
        kv.put("payType", String.valueOf(payType));
        kv.put("couponId", String.valueOf(couponId));

        String str = restTemplate.getForObject(buildApi(server, BALANCESIGNPAY_CHECK), String.class, kv);
        JSONObject object = JSON.parseObject(str);
        boolean success = object.getBoolean("success");
        String message = null;
        if (!success) {
            message = object.getString("message");
        }

        return new ResultVo(success, message);

    }

    public ResultVo orderPay(String server, Long orderId) {

        Map<String, String> kv = new HashMap<String, String>();
        kv.put("orderId", String.valueOf(orderId));

        String str = restTemplate.postForObject(buildApi(server, ORDER_PAY), null, String.class, kv);
        JSONObject object = JSON.parseObject(str);
        boolean success = object.getBoolean("success");
        String message = null;
        if (!success) {
            message = object.getString("message");
        }

        // Map<String, String> map = new HashMap<String, String>();
        // map.put("drivers", drivers);
        // map.put("employId", String.valueOf(employId));
        // String result =
        // restTemplate.postForObject(buildApi(server, SIMPLECARPOOL_V4), null,
        // String.class, map);
        // return JSON.parseObject(result, ResultTransport.class);

        return new ResultVo(success, message);

    }

    /**
     * 获取微信v5版本的广告位
     *
     * @param server      服务器地址
     * @param serviceType 业务类型
     * @return
     */
    public String getWeixinV5News(String server, Long companyId, String serviceType) {
        return restTemplate.getForObject(buildApi(server, GET_WEIXIN_V5_NEWS), String.class, companyId, serviceType);
    }

    /**
     * 获取代驾项目后台APP设置信息
     *
     * @param server 代驾项目主机地址
     * @return
     */
    public JSONObject getAppSettingV5(String server) {
        String response = restTemplate.getForObject(buildApi(server, APP_SETTING_V5), String.class);
        return JSON.parseObject(response);
    }

    /**
     * 获取代驾项目支付设置
     *
     * @param server 代驾项目主机地址
     * @return
     */
    public JSONObject getPaySettingV5(String server) {
        String response = restTemplate.getForObject(buildApi(server, GET_PAY_SETTING_V5), String.class);
        return JSON.parseObject(response);
    }

    /**
     * 微信公众号V5修改乘客信息
     *
     * @param server    代驾地址
     * @param phone     电话
     * @param appKey    系统Key
     * @param name      姓名
     * @param gender    性别
     * @param memberEcp 紧急电话
     * @param address   常用目的地
     * @param lat       常用目的地lat
     * @param lng       常用目的地lng
     * @return
     */
    public boolean updatePassengerInfoV5(String server, String phone, String appKey, String name, Integer gender,
                                         String memberEcn, String memberEcp, String address, Double lat, Double lng) {

        String api = UPDATE_PASSENGER_V5 + "?phone={phone}" + "&appKey={appKey}" + "&name={name}" + "&gender={gender}"
                + "&memberEcn={memberEcn}" + "&memberEcp={memberEcp}" + "&address={address}" + "&lng={lng}"
                + "&lat={lat}";

        // 修改
        String rs = restTemplate.postForObject(buildApi(server, api), null, String.class, phone, appKey, name, gender,
                memberEcn, memberEcp, address, lng, lat);

        JSONObject json = JSONObject.parseObject(rs);
        if (json.getBooleanValue("success")) {
            return true;
        }
        System.out.println("更新乘客信息失败 ==> " + json.toString());
        return false;
    }

    /**
     * 微信V5分页获取订单
     *
     * @param server      代驾地址
     * @param passengerId 乘客地址
     * @param page        页码
     * @param rows        数据量
     * @return
     */
    public Map<String, Object> getOrdersV5(String server, Long passengerId, Integer page, Integer rows) {
        Map<String, Object> returnMap = new HashMap<String, Object>();

        final String api = GET_ORDERS_V5 + "?passengerId={passengerId}" + "&page={page}" + "&rows={rows}";

        String rs = restTemplate.getForObject(buildApi(server, api), String.class, passengerId, page, rows);

        JSONObject json = JSONObject.parseObject(rs);
        if (!json.getBooleanValue("success")) {
            throw new RuntimeException();
        }

        JSONObject data = json.getJSONObject("data");
        returnMap.put("total", data.getInteger("total"));
        returnMap.put("rows", data.getJSONArray("orderList"));
        return returnMap;
    }

    /**
     * V5分页获取资金流水
     */
    private static final String GET_CAPITAL_RECORDS_V5 = "member/api/rest/v3/pagePaymentsByMemberV5";

    /**
     * V5分页获取用户资金流水
     *
     * @param server  代驾地址
     * @param phone   电话
     * @param page    页码
     * @param rows    条数
     * @param payType 获取的流水类型
     * @return
     */
    public ResultV5 capitalRecordsV5(String server, String phone, Integer page, Integer rows, String payType) {

        ResultV5 result = ErrorMapV5.ERR_SUCCESS.clone();

        String api = GET_CAPITAL_RECORDS_V5 + "?phone={phone}" + "&page={page}" + "&limit={limit}";

        String rs = null;
        if (null != payType) {
            api = api + "&payType={payType}";
            rs = restTemplate.postForObject(buildApi(server, api), null, String.class, phone, page, rows, payType);
        } else {
            rs = restTemplate.postForObject(buildApi(server, api), null, String.class, phone, page, rows);
        }

        if (null == rs) {
            return ErrorMapV5.ERR_GET_CAPITAL_RECORDS;
        }

        JSONObject json = JSONObject.parseObject(rs);
        if (json.getIntValue("code") == 0) {
            JSONObject data = json.getJSONObject("data");
            result.setData(data);
        } else {
            return ErrorMapV5.ERR_GET_CAPITAL_RECORDS;
        }
        return result;
    }

    /**
     * V5分页获取乘客优惠券
     */
    public static final String GET_COUPONS_V5 = "member/api/rest/v3/queryCouponsV5";

    /**
     * V5分页获取乘客优惠券
     *
     * @param server 代驾地址
     * @param phone  电话
     * @param page   页码
     * @param rows   条数
     * @return
     */
    public ResultV5 getCouponsV5(String server, String phone, Integer page, Integer rows, Integer status) {
        ResultV5 result = ErrorMapV5.ERR_SUCCESS.clone();

        String api = GET_COUPONS_V5 + "?phone={phone}" + "&page={page}" + "&limit={limit}" + "&status={status}";

        String rs = restTemplate.postForObject(buildApi(server, api), null, String.class, phone, page, rows, status);

        JSONObject json = JSONObject.parseObject(rs);
        if (json.getIntValue("code") == 0) {
            JSONObject data = json.getJSONObject("data");
            result.setData(data);
        } else {
            return ErrorMapV5.ERR_GET_COUPONS_V5;
        }
        return result;
    }

    /**
     * v5优惠券绑定（添加）
     */
    public static final String COUPON_BIND_V5 = "member/api/rest/v3/couponBindV5";

    /**
     * v5优惠券绑定（添加）
     *
     * @param server
     * @param phone
     * @param code
     * @param codeKey
     * @return
     */
    public ResultV5 couponsBindV5(String server, String phone, String code, String codeKey) {
        ResultV5 result = ErrorMapV5.ERR_SUCCESS.clone();

        String api = COUPON_BIND_V5 + "?phone={phone}" + "&code={code}" + "&codeKey={codeKey}";

        String rs = restTemplate.postForObject(buildApi(server, api), null, String.class, phone, code, codeKey);

        JSONObject json = JSONObject.parseObject(rs);
        if (json.getIntValue("code") == 0) {
            JSONObject data = json.getJSONObject("data");
            result.setData(data);
        } else {
            return ErrorMapV5.ERR_COUPON_BIND_V5;
        }
        return result;
    }

    /**
     * 微信公众号V5分页获取通知
     */
    public static final String GET_NOTICE_V5 = "member/api/rest/v3/pageNoticeV5";

    /**
     * 微信公众号V5分页获取通知
     *
     * @param server      代驾地址
     * @param passengerId 客户id
     * @param page        页码
     * @param rows        条数
     * @return
     */
    public ResultV5 getNoticeV5(String server, Long passengerId, Integer page, Integer rows) {
        ResultV5 result = ErrorMapV5.ERR_SUCCESS.clone();

        String api = GET_NOTICE_V5 + "?memberId={memberId}" + "&page={page}" + "&limit={limit}";

        String rs = restTemplate.getForObject(buildApi(server, api), String.class, passengerId, page - 1, rows);

        JSONObject json = JSONObject.parseObject(rs);
        if (json.getIntValue("code") == 0) {
            JSONObject data = json.getJSONObject("data");
            result.setData(data);
        } else {
            return ErrorMapV5.ERR_GET_NOTICE_V5;
        }
        return result;
    }

    /**
     * V5获取用户未读通知
     */
    private static final String GET_NOT_READ_NOTICES_V5 = "member/api/rest/v3/getNotReadNoticesV5";

    /**
     * V5获取用户未读通知
     *
     * @param server      代驾地址
     * @param passengerId 客户ID
     * @return
     */
    public JSONObject getNotReadNoticesV5(String server, Long passengerId) {
        String api = GET_NOT_READ_NOTICES_V5 + "?passengerId={passengerId}";
        String rs = restTemplate.getForObject(buildApi(server, api), String.class, passengerId);
        JSONObject json = JSONObject.parseObject(rs);
        return json;
    }

    /**
     * 微信公众号V5更新通知已读
     */
    public static final String UPDATE_NOTICE_READ_V5 = "member/api/rest/v3/readNoticeV5";

    /**
     * 微信公众号V5更新通知已读
     *
     * @param server      代驾地址
     * @param passengerId 客户ID
     * @param noticeId    通知ID
     * @return
     */
    public ResultV5 updateNoticeRead(String server, Long passengerId, Long noticeId) {
        String api = UPDATE_NOTICE_READ_V5 + "?passengerId={passengerId}" + "&noticeId={noticeId}";

        String rs = restTemplate.postForObject(buildApi(server, api), null, String.class, passengerId, noticeId);

        JSONObject json = JSONObject.parseObject(rs);
        if (json.getIntValue("code") == 0) {
            return ErrorMapV5.ERR_SUCCESS.clone();
        } else {
            return ErrorMapV5.ERR_UPDATE_NOTICE_READ_V5;
        }
    }

    /**
     * 微信V5获取通知详情
     */
    public static final String GET_NOTICE_INFO_V5 = "member/api/rest/v3/noticeInfoV5";

    /**
     * 微信V5获取通知详情
     *
     * @param server      代驾地址
     * @param passengerId 客户ID
     * @param noticeId    通知ID
     * @return
     */
    public ResultV5 getNoticeInfoV5(String server, Long passengerId, Long noticeId) {
        ResultV5 result = ErrorMapV5.ERR_SUCCESS.clone();

        String api = GET_NOTICE_INFO_V5 + "?passengerId={passengerId}" + "&id={id}";

        String rs = restTemplate.getForObject(buildApi(server, api), String.class, passengerId, noticeId);

        JSONObject json = JSONObject.parseObject(rs);
        if (json.getIntValue("code") == 0) {
            result.setData(json.getJSONObject("data"));
            return result;
        } else {
            return ErrorMapV5.ERR_GET_NOTICE_INFO_V5;
        }
    }

    /**
     * 微信V5获取用户协议
     */
    public static final String GET_AGREEMENT_TEXT_V5 = "member/api/rest/v3/agreementText";

    /**
     * 微信V5获取用户协议
     *
     * @param server    代驾地址
     * @param acKey
     * @param companyId 公司id
     * @param lat       公司 lat
     * @param lng       公司 lng
     * @return
     */
    public ResultV5 getAgreementTextV5(String server, String acKey, Long companyId, Double lat, Double lng) {
        ResultV5 result = ErrorMapV5.ERR_SUCCESS.clone();

        String api = GET_AGREEMENT_TEXT_V5 + "?acKey={acKey}" + "&companyId={companyId}" + "&longitude={longitude}"
                + "&latitude={latitude}";

        String rs = restTemplate.getForObject(buildApi(server, api), String.class, acKey, companyId, lng, lat);
        result.setData(rs);
        return result;
    }

    /**
     * V5微信公众号申请发票
     */
    public static final String CREATE_RECEIPT_V5 = "member/api/rest/v3/createReceiptV5";

    /**
     * V5微信公众号申请发票
     *
     * @param server
     * @param phone
     * @param appKey
     * @param money
     * @param type
     * @param memo
     * @return
     */
    public ResultV5 createReceiptV5(String server, String phone, String appKey, BigDecimal money, String type,
                                    String memo) {
        ResultV5 result = ErrorMapV5.ERR_SUCCESS.clone();

        String api = CREATE_RECEIPT_V5 + "?appKey={appKey}" + "&phone={phone}" + "&money={money}" + "&type={type}"
                + "&memo={memo}";

        String rs = restTemplate.postForObject(buildApi(server, api), null, String.class, appKey, phone, money, type,
                memo);

        JSONObject json = JSONObject.parseObject(rs);
        if (json.getIntValue("code") == 0) {
            JSONObject data = json.getJSONObject("data");
            result.setData(data);
        } else {
            return ErrorMapV5.ERR_CREATE_RECEIPT_V5;
        }
        return result;
    }

    /**
     * v5微信获取客户发票申请记录
     */
    public static final String QUERY_RECEIPT_V5 = "member/api/rest/v3/queryReceiptV5";

    /**
     * v5微信获取客户发票申请记录
     *
     * @param server 代驾地址
     * @param appKey 系统KEY
     * @param phone  电话
     * @param page   页码
     * @param rows   条数
     * @return
     */
    public ResultV5 queryReceiptV5(String server, String appKey, String phone, Integer page, Integer rows) {
        ResultV5 result = ErrorMapV5.ERR_SUCCESS.clone();

        String api = QUERY_RECEIPT_V5 + "?appKey={appKey}" + "&phone={phone}" + "&page={page}" + "&limit={limit}";

        String rs = restTemplate.postForObject(buildApi(server, api), null, String.class, appKey, phone, page - 1,
                rows);

        JSONObject json = JSONObject.parseObject(rs);
        if (json.getIntValue("code") == 0) {
            JSONObject data = json.getJSONObject("data");
            result.setData(data);
        } else {
            return ErrorMapV5.ERR_QUERY_RECEIPT_V5;
        }
        return result;
    }

    /**
     * 获取用户的紧急联系人和常用目的地
     *
     * @param server      代驾地址
     * @param appKey      系统Key
     * @param passengerId 客户Id
     * @return
     */
    public JSONObject getPassengerEcnEcpAndAddress(String server, String appKey, Long passengerId) {
        String apiAddress = "api/passenger/getPassengerEcnEcpAndAddress" + "?passengerId={passengerId}"
                + "&appKey={appKey}";
        String api = buildApi(server, apiAddress);
        String rs = restTemplate.getForObject(api, String.class, passengerId, appKey);
        if (null != rs) {
            JSONObject json = JSONObject.parseObject(rs);
            if (json.getBooleanValue("success")) {
                JSONObject data = json.getJSONObject("data");
                return data;
            }
        }
        return null;
    }

    /**
     * 微信V5客户余额充值
     *
     * @param server      代驾地址
     * @param passengerId 客户ID
     * @param money       充值金额
     * @param openId      微信openid
     * @return
     */
    public JSONObject addbalance(String server, Long passengerId, BigDecimal money, String openId) {
        String apiAddress = "member/api/rest/v4/pay/wx/weixinRecharge" + "?passengerId={passengerId}" + "&money={money}"
                + "&openId={openId}";

        String api = buildApi(server, apiAddress);
        String rs = restTemplate.postForObject(api, null, String.class, passengerId, money, openId);
        if (null != rs) {
            JSONObject json = JSONObject.parseObject(rs);
            if (json.getIntValue("code") == 0) {
                return json;
            }
        }
        return null;
    }

    /**
     * 微信V5获取跑腿预算费用
     *
     * @param areaId  收费ID
     * @param time    预算时间（分钟）
     * @param mileage 预算的公里
     * @return
     */
    public JSONObject getPaoTuiPrice(String server, Long areaId, Integer time, Double mileage) {

        String apiAddress = "member/api/rest/v3/getNewPrice" + "?areaId={areaId}" + "&time={time}"
                + "&mileage={mileage}";
        String api = buildApi(server, apiAddress);
        String rs = restTemplate.getForObject(api, String.class, areaId, time, mileage);
        if (null != rs) {
            JSONObject json = JSONObject.parseObject(rs);
            return json;
        }
        return null;
    }

    /**
     * 微信V5获取跑腿用户优惠券
     *
     * @param server       代驾地址
     * @param passengerId  用户ID
     * @param couponTypeId 优惠券类型ID
     * @return
     */
    public JSONObject getPaoTuiCoupons(String server, Long passengerId, Long couponTypeId) {

        String apiAddress = "api/errand/listValidCouponsByPassengerV5" + "?passengerId={passengerId}";

        String api = null;
        String rs = null;
        if (null != couponTypeId) {
            apiAddress = apiAddress + "&couponTypeId={couponTypeId}";
            api = buildApi(server, apiAddress);
            rs = restTemplate.getForObject(api, String.class, passengerId, couponTypeId);
        } else {
            api = buildApi(server, apiAddress);
            rs = restTemplate.getForObject(api, String.class, passengerId);
        }

        if (null != rs) {
            JSONObject json = JSONObject.parseObject(rs);
            return json;
        }
        return null;
    }

    /**
     * 获取用户推荐返利详情
     *
     * @param server      代驾地址
     * @param passengerId 客户ID
     * @param payType     支付类型
     * @param page        页码
     * @param rows        条数
     * @return
     */
    public JSONObject getRecommendRebateByPassenger(String server, Long passengerId, String payType, Integer page,
                                                    Integer rows) {
        String apiAddress = "api/passenger/getRecommendRebateByPassenger" + "?passengerId={passengerId}"
                + "&payType={payType}" + "&page={page}" + "&rows={rows}";

        String api = buildApi(server, apiAddress);
        String rs = restTemplate.getForObject(api, String.class, passengerId, payType, page, rows);

        if (null != rs) {
            JSONObject json = JSONObject.parseObject(rs);
            return json;
        }
        return null;
    }

    /**
     * 获取主公司
     *
     * @param server 代驾地址
     * @return
     */
    public JSONObject getMianCompany(String server) {
        String apiAddress = "api/company/main";
        String api = buildApi(server, apiAddress);
        String rs = restTemplate.getForObject(api, String.class);
        if (null != rs) {
            JSONObject json = JSONObject.parseObject(rs);
            return json;
        }
        return null;
    }

    /**
     * 获取 货运的当日最大下单量
     *
     * @param server      代驾地址
     * @param appKey      系统key
     * @param passengerId 客户id
     * @return
     */
    public boolean isCreateOrderNumberFreight(String server, String appKey, Long passengerId) {
        String apiAddress = "api/passenger/getCreateOrderNumberFreight" + "?passengerId={passengerId}"
                + "&appKey={appKey}";
        String api = buildApi(server, apiAddress);
        String rs = restTemplate.getForObject(api, String.class, passengerId, appKey);
        if (rs.equals("true")) {
            return true;
        }
        return false;
    }

    /**
     * 获取 跑腿的当日最大下单量
     *
     * @param server      代驾地址
     * @param appKey      系统key
     * @param passengerId 客户id
     * @return
     */
    public boolean isCreateOrderNumberErrand(String server, String appKey, Long passengerId) {
        String apiAddress = "api/passenger/getCreateOrderNumberErrand" + "?passengerId={passengerId}"
                + "&appKey={appKey}";
        String api = buildApi(server, apiAddress);
        String rs = restTemplate.getForObject(api, String.class, passengerId, appKey);
        if (rs.equals("true")) {
            return true;
        }
        return false;
    }

    /**
     * 获取首页广告位
     *
     * @param address   代驾地址
     * @param companyId 公司id
     * @param contType  移动端类型，微信心痛默认为weixin
     */
    public JSONObject getHomeAdv(String address, Long companyId, String contType) {
        String apiAddress = "member/api/rest/v3/homeAdv?companyId={companyId}&contType={contType}";
        String api = buildApi(address, apiAddress);
        String rs = restTemplate.getForObject(api, String.class, companyId, contType);
        if (null != rs) {
            JSONObject json = JSONObject.parseObject(rs);
            return json;
        }
        return null;
    }

    /**
     * 获取专车司机信息.
     */

    public JSONObject getZhuanDriver(String server, Long id) {
        String response = restTemplate.getForObject(buildApi(server, GET_ZHUAN_DRIVER), String.class, id);
        JSONObject jsonObject = JSON.parseObject(response);
        return jsonObject;
    }

    /**
     * 获取微信二维码.
     */
    public String getWxQrCode(String server) {
        try {
            String response = restTemplate.getForObject(buildApi(server, GET_WX_QRCODE), String.class);
            JSONObject jsonObject = JSON.parseObject(response);
            JSONObject data = JSON.parseObject(jsonObject.getString("data"));
            String wxQrCode = data.getString("wxQrCode");
            return wxQrCode;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * V4确认费用重量预算费用.
     */
    public ResultTransport getErrandWeightPriceV4(String server, Long orderId, Double weight, Double mileage) {
        Map<String, String> kv = new HashMap<String, String>();
        kv.put("orderId", String.valueOf(orderId));
        if (null == weight) {
            weight = 0D;
        }
        if (null == mileage) {
            mileage = 0D;
        }
        kv.put("weight", String.valueOf(weight));
        kv.put("mileage", String.valueOf(mileage));
        String result = restTemplate.getForObject(buildApi(server, GET_PRICE_BY_WEIGHT_V4), String.class, kv);

        ResultTransport transport = JSON.parseObject(result, ResultTransport.class);

        return transport;
    }

    @Value("${module.passenger.appId}")
    private String passengerAppId;

    @Value("${module.passenger.appKey}")
    private String passengerAppKey;

    public static final String CREATE = "api/passenger/bindOrCreatePassengerForWeixinIntroduce";

    public Passenger create(String server, Passenger passenger, Long driverId, String appKey, boolean update) {

        StringBuilder sb = new StringBuilder();
        sb.append(buildApi(server, CREATE));
        sb.append("?appKey={appKey}");
        Map<String, String> kv = new HashMap<String, String>();

        kv.put("appKey", appKey);
        if (null != driverId) {
            kv.put("driverId", String.valueOf(driverId));
            sb.append("&driverId={driverId}");
        }
        if(update) {
            kv.put("update", String.valueOf(update));
            sb.append("&update={update}");
        }
        String reponse = restTemplate.postForObject(sb.toString(), passenger, String.class, kv);

        JSONObject jsonObject = JSON.parseObject(reponse);

        if (jsonObject.getIntValue("code") == 0) {

            return jsonObject.getObject("result", Passenger.class);
        }

        return null;
    }
}
